gpt4 book ai didi

ios - 全局化 UIAlertView

转载 作者:行者123 更新时间:2023-11-29 04:05:24 26 4
gpt4 key购买 nike

我想知道,如果我在 View Controller A中分配一个UIAlertView,我可以从 View Controller B访问它的响应吗?

例如

View Controller A

UIAlertView *alert;
alert = [[UIAlertView alloc] init];
[alert setTitle:@"Confirm"];
[alert setMessage:@"Do you pick Yes or No?"];
[alert setDelegate:self];
[alert addButtonWithTitle:@"Yes"];
[alert addButtonWithTitle:@"No"];
[alert show];

View Controller B

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView == alert)
{

}
}

感谢您的帮助

最佳答案

如果您将警报 View 的委托(delegate)设置为 ViewController B,则可以。

[alert setDelegate:self];

成为

[alert setDelegate:viewControllerB];

我正在处理的代码库的示例:

// Creating the view controller
AreaListController *descendentAreas = [[AreaListController alloc] init];

// Setting the delegate
[alert setDelegate:descendentAreas];

// Pushing the view controller
[self pushViewController:descendentAreas];

关于ios - 全局化 UIAlertView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15345794/

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