Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 使用示例UIAlertViewDelegate了解协议实现_Iphone - Fatal编程技术网

Iphone 使用示例UIAlertViewDelegate了解协议实现

Iphone 使用示例UIAlertViewDelegate了解协议实现,iphone,Iphone,有两类A和B: @接口A:NSObject{…}@end @接口B{…} A将通过创建B来使用B并使用它 在B中,有机会创建UIAlertViewDialog,并进行一些用户交互 我认为在类A中实现ClickedButtonIndex是合理的,因为声明A是为了确认UIAlertViewDelegate。但事实是我们应该在B中实现 (无效)警报视图:(UIAlertView*)警报单击按钮索引:(NSInteger)按钮索引 {//bla bla} 我真的不明白像这种情况下确认协议的真正原因是

有两类A和B:

@接口A:NSObject{…}@end

@接口B{…}

A将通过创建B来使用B并使用它

在B中,有机会创建UIAlertViewDialog,并进行一些用户交互

我认为在类A中实现ClickedButtonIndex是合理的,因为声明A是为了确认UIAlertViewDelegate。但事实是我们应该在B中实现

  • (无效)警报视图:(UIAlertView*)警报单击按钮索引:(NSInteger)按钮索引 {//bla bla}
我真的不明白像这种情况下确认协议的真正原因是什么


提前谢谢

创建UIAlertView时,您可以定义什么是委托类:

UIAlertView *alert = [[UIAlertView alloc]
          initWithTitle: title
          message: message
          delegate: delegate
          cancelButtonTitle: firstButtonName
          otherButtonTitles: nil];

因此,如果您在B类中创建UIAlertView,但您希望在A类中点击按钮时做出反应,则需要将上述代码中的委托设置为A类。

如果您能够接受答案(通过单击复选标记),如果它是您要查找的信息,那将非常好;)