gpt4 book ai didi

iphone - 我需要添加 协议(protocol)吗?

转载 作者:行者123 更新时间:2023-12-03 20:58:53 24 4
gpt4 key购买 nike

我添加了一个alertView来向用户显示警报消息(见下文)

-(void)connectionAlert {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView"
message:@"<Alert message>"
delegate:self
cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[alert release];
}

然后我使用 [self connectionAlert]; 从我的 viewController 调用它一切正常,但我不确定是否应该添加 <UIAlertViewDelegate>我的 viewController 接口(interface)的协议(protocol)。

目前我添加了协议(protocol),并且一切似乎都正常工作,这是因为我通过自身调用 UIAlertView 吗?我真的应该添加协议(protocol)吗?

非常感谢

加里

最佳答案

我个人从来没有添加过 UIAlertViewDelegate 协议(protocol),所以我不明白为什么你必须这样做。

仅当您希望访问以下方法时才需要该协议(protocol):

响应操作

– alertView:clickedButtonAtIndex:

自定义行为

– willPresentAlertView:
– didPresentAlertView:
– alertView:willDismissWithButtonIndex:
– alertView:didDismissWithButtonIndex:

取消

– alertViewCancel:

如果您不想听这些通知,则不需要协议(protocol)。

关于iphone - 我需要添加 <UIAlertViewDelegate> 协议(protocol)吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2699741/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com