从AppDelegate展示UIAlertController [英] Present UIAlertController from AppDelegate
本文介绍了从AppDelegate展示UIAlertController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正试图在我的iOS应用程序中从AppDelegate呈现 UIAlertController
。
以下是警报和现在的方法。
I'm trying to present a UIAlertController
from the AppDelegate in my iOS app.
Below is the alert and the present method.
UIAlertController *alert = [UIAlertController alertControllerWithTitle:cTitle message:cMessage preferredStyle:UIAlertControllerStyleAlert];
//Configure alert and actions
[self.window.rootViewController presentViewController:alert animated:TRUE completion:nil];
但是,当我尝试提示警报时,它不会出现,我收到以下警报在控制台中。
However, when I try to present the alert, it doesn't appear and I get the following alert in the console.
Warning: Attempt to present <UIAlertController: 0x145f5d60> on <UINavigationController: 0x146590f0> whose view is not in the window hierarchy!
导致错误的原因是什么以及如何解决?
What is causing the error and how do I fix it?
推荐答案
如果你想从didFinishLaunchingWithOptions.Hope启动它,也可以使用这段代码。这有帮助。
You can use this code as well if you want to launch it from didFinishLaunchingWithOptions.Hope this helps.
dispatch_async(dispatch_get_main_queue(), {
let importantAlert: UIAlertController = UIAlertController(title: "Action Sheet", message: "Hello I was presented from appdelegate ;)", preferredStyle: .ActionSheet)
self.window?.rootViewController?.presentViewController(importantAlert, animated: true, completion: nil)
})
这篇关于从AppDelegate展示UIAlertController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文