(IOS)在非ViewController的地方弹出UIAlertController对话框

//  最好抽成一个分类

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Title" message:@"message" preferredStyle:UIAlertControllerStyleAlert];

//...

id rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;

if([rootViewController isKindOfClass:[UINavigationController class]])

{

    rootViewController = ((UINavigationController *)rootViewController).viewControllers.firstObject;

}

if([rootViewController isKindOfClass:[UITabBarController class]])

{

    rootViewController = ((UITabBarController *)rootViewController).selectedViewController;

}

[rootViewController presentViewController:alertController animated:YEScompletion:nil];

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 自从iOS9出来之后,需要使用UIAlertController来弹出弹框,不在提倡使用UIAlertView了,...
    南京杨小兵阅读 3,619评论 1 0
  • 1、禁止手机睡眠 [UIApplication sharedApplication].idleTimerDisab...
    小小夕舞阅读 5,407评论 1 1
  • 转自:https://www.jianshu.com/p/10b2323f502e 1、禁止手机睡眠 [UIApp...
    aggie1024阅读 7,701评论 0 6
  • 哈哈,我今天真的是很“小欢喜”啊。因为今天是中秋节,明明可以大欢喜的,可是因为今天下雨了,所以心情有点糟。今天上午...
    南师附中宿迁分校王静云阅读 1,787评论 0 0
  • 很多人在读历史的时候会注意到这么一个问题:为什么春秋战国、三国、清末民初等我们熟知的“乱世”时期,经常人才辈出、群...
    冷历史观阅读 11,840评论 6 4

友情链接更多精彩内容