ios - 如何在Appdelegate中通过获取keyWindow来present一个UIViewAlertViewController
高洛峰
高洛峰 2017-04-17 17:51:47
0
4
277

1.问题描述

我想要在- (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions中弹出present出一个UIViewAlertViewController,效果就是在启动页的时候弹出更新提示,但是因为当前的这个window还没有成为keyWindow,所以在启动页消失后,层次图就会变成下面这样。

是否只能等首页出现弹出UIAlertViewController才能正确的在keyWindow上弹出?

2.代码

[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alertControler animated:YES completion:^{
                
}];

也使用过

UIWindow *window = [UIApplication sharedApplication].delegate.window;
[window makeKeyAndVisible];
[window.rootViewController presentViewController:alertControler animated:YES completion:^{
                
}];

3.请教

1.怎么样才是正确的姿势。。。
2.是否是因为当前的keyWindow和启动图过后出现首页时的keyWindow不同。(我觉得是这个原因)

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(4)
Ty80

According to your needs, you should operate in the startup page, not the entry class

左手右手慢动作

Why not test it, print their addresses and see if they are the same?

刘奇

Can’t I use navigation to push?

巴扎黑

Why do you have to use keywindow? Can’t you use navigation controller or tabBarController?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template