简体   繁体   中英

Change ViewController from the AppDelegate

Im trying to change ViewController from my AppDelegate when i receive a notification.

Here is what i've got so far:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{

    if (application.applicationState == UIApplicationStateInactive)
    {
        self.convViewController = self.window.rootViewController;

    }
    else if(application.applicationState == UIApplicationStateActive)
    {
        self.convViewController = self.window.rootViewController;

    }
}

I'm referencing my ViewController like this (in the .h file):

@property (strong, nonatomic) ConvViewController *convViewController;

However, when i click on a notification nothing happens.

Any ideas?

Set:

self.window.rootViewController = self.convViewController;

You're assigning the wrong property. You need to be setting the window's view controller to change the view controller presented by the window.

In the above code you are setting you're convViewController to be a pointer to the window rootViewController.

Switch your logic:

self.window.rootViewController = self.convViewController;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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