前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >UIViewController present UIViewController 的问题

UIViewController present UIViewController 的问题

原创
作者头像
SheltonWan
发布2019-07-05 16:33:49
9550
发布2019-07-05 16:33:49
举报

今天写了个demo才发现,当尝试在函数:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool

或者

RootViewController中的viewDidload

中调用present来弹出一个警告窗口(由UIAlertController创建的controller),这时候无法弹出窗口,并出现如下警告:

Warning: Attempt to present <UIAlertController: 0x102809200> on <SwiftDemoApp.ViewController: 0x10140db60> whose view is not in the window hierarchy!

究其原因是A present B,而A还没有完成显示步骤(whose view is not in the window hierarchy),正常情况下我们需要在viewDidAppear之后才能成功present另一个viewController。

通过尝试,找到了一种解决方案,通过performSelectoronMainThread方法,必须将waitUntilDone的参数设为false。通过异步串行的模式,我们可以使得弹出窗口的时间点会在viewDidAppear后被执行。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档