今天写了个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 删除。