Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 348
mikeholp Avatar asked Oct 18 '13 06:10

mikeholp


People also ask

How do I present a view controller from another view controller?

You may also start segues from table rows and collection view cells. Right-click the control or object in your current view controller. Drag the cursor to the view controller you want to present. Select the kind of segue you want from the list that Xcode provides.

What is an app delegate?

The app delegate is effectively the root object of your app, and it works in conjunction with UIApplication to manage some interactions with the system. Like the UIApplication object, UIKit creates your app delegate object early in your app's launch cycle so it's always present.


1 Answers

You can also try:

[[[UIApplication sharedApplication] keyWindow] rootViewController] 

How I use it:

#define ROOTVIEW [[[UIApplication sharedApplication] keyWindow] rootViewController] [ROOTVIEW presentViewController:interstitialViewController animated:YES completion:^{}]; 
like image 101
WrightsCS Avatar answered Sep 28 '22 04:09

WrightsCS