OGeek|极客世界-中国程序员成长平台

标题: ios - appdelegate.m 中的 UIAlertView 不起作用 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 20:47
标题: ios - appdelegate.m 中的 UIAlertView 不起作用

我已经在谷歌上搜索了将近一整天的时间,但没有找到任何解决方案,所以我想问你们......

我正在开发一个 iOS 应用程序,该应用程序应通过 WiFi 连接到 mbed,并在连接时为用户提供一个对话框,如果未连接,则为用户提供重试的可能性。 我的问题是现在我已经在 appdelegate.m 中实现了连接方法,我想从这里显示警报..

它自己的警报工作正常,但我在检测按下按钮时遇到问题,没有调用 clickedButtonAtIndex。

我在 appdelegate.h 中添加了 UIAlertViewDelegate,如下所示:

@interface AppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate, UIAlertViewDelegate> 

并在警报 View 中将委托(delegate)设置为 self,如下所示:

alert_NOT = [[UIAlertView alloc] initWithTitle"Not connected!" message:message_to_user delegate:self cancelButtonTitle"Try again" otherButtonTitles: nil];
    [alert_NOT show];
    [alert_NOT release]

clickedButtonAtIndex 看起来像

- (void)alertViewUIAlertView *)alertView clickedButtonAtIndexNSInteger)buttonIndex {
NSLog(@"test");

}

因此,当在警报 View 中按下按钮时,我希望在日志中看到“测试”一词,但没有任何反应。

更新: 尝试在我的“FirstViewController.m”中实现它并且它在那里工作:S 但如果可能的话,我非常希望将它放在 appdelegate.m 中..



Best Answer-推荐答案


我目前正在研究类似的实现,并想与您分享一个想法:也许使用 NSNotification 在您的委托(delegate)条件满足时触发,可以在您的 VC 中监听并处理适本地,在堆栈顶部带有警报 View 。

关于ios - appdelegate.m 中的 UIAlertView 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8601274/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4