A类和B类有两种:
@接口A: NSObject < UIAlertViewDelegate >{.} @end
@接口B{.}
A将通过创建B来使用B并使用它。
在B中,有机会创建UIAlertViewDialog,并进行一些用户交互。
我认为在A类中实现clickedButtonAtIndex是合理的,因为A被声明为向UIAlertViewDelegate确认。但事实是,我们应该在B中实施。
我真的不明白像这样确认协议的真正原因是什么。
提前谢谢。
发布于 2010-06-25 10:23:26
在创建UIAlertView时,定义什么将是委托类:
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: title
message: message
delegate: delegate
cancelButtonTitle: firstButtonName
otherButtonTitles: nil];因此,如果您在B类中创建了UIAlertView,但是您想对A类中的按钮点击作出反应,则需要将上面代码中的委托设置为A类。
https://stackoverflow.com/questions/3116551
复制相似问题