gpt4 book ai didi

iphone - UIAlertView 代表

转载 作者:太空狗 更新时间:2023-10-30 03:13:18 27 4
gpt4 key购买 nike

有人可以解释 UIAlertView 的委托(delegate)是如何工作的吗?它是自动调用还是我必须调用它?例如:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

最佳答案

假设您在代表是“自己”的地方显示了一个警报

- (void)showAlert {
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"My Alert"
message:@"Do you want to continue?"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"No", @"Yes", nil];
[myAlert show];
[myAlert release];
}

为了使以下内容在您的 .m 文件中起作用:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

您的 .h 文件需要在实现语句中引用 UIAlertViewDelegate,如下所示:

@interface myViewController : UIViewController <UIAlertViewDelegate> {
}

这是允许您的 .m 文件响应 UIAlertViewDelegate 方法调用的原因。

关于iphone - UIAlertView 代表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3826659/

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