Alosyius
Alosyius

Reputation: 9151

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?

Upvotes: 1

Views: 1752

Answers (2)

Aaron Bratcher
Aaron Bratcher

Reputation: 6471

Switch your logic:

self.window.rootViewController = self.convViewController;

Upvotes: 0

Infinity James
Infinity James

Reputation: 4735

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.

Upvotes: 1

Related Questions