简体   繁体   English

从应用程序委托呈现视图控制器

[英]Present view controller from app delegate

I'm attempting to present a view controller from the app delegate with this code:我正在尝试使用以下代码从应用程序委托呈现一个视图控制器:

- (void)interstitialViewControllerRequestSucceeded:(UIViewController *)interstitialViewController
{
    [self.window.rootViewController presentViewController:(UIViewController *)interstitialViewController animated:YES completion:NULL];
}

It will display the interstitial on the initial view controller but none of the others.它将在初始视图控制器上显示插页式广告,但不显示其他任何内容。 I want it to display on every one attached to a navigation controller.我希望它显示在连接到导航控制器的每个控制器上。

How can I modify this code to achieve that goal?如何修改此代码以实现该目标?

You can also try:你也可以试试:

[[[UIApplication sharedApplication] keyWindow] rootViewController]

How I use it:我如何使用它:

#define ROOTVIEW [[[UIApplication sharedApplication] keyWindow] rootViewController]
[ROOTVIEW presentViewController:interstitialViewController animated:YES completion:^{}];

用于检查响应的 Swift 3 版本:

UIApplication.shared.keyWindow?.rootViewController

Swift 5 and up Swift 5 及以上

Check this:检查这个:

UIApplication.shared.windows.first?.rootViewController

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM