문제

I am trying to change from the App delegate method to the Master View when I receive a Remote Notification, in order to perform a segue in the Master View to another view, but I am getting an NSInvalidArgumentException

Code in App Delegate when didReceiveRemoteNotification:

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

    EmergencyMasterViewController* maincontroller = (EmergencyMasterViewController*)self.window.rootViewController;
    [maincontroller alert];
}

Code in MasterView:

-(void)alert
{
    [self performSegueWithIdentifier: @"Warning" sender: self];
}

And the error I am getting: [UINavigationController alert]: unrecognized selector

도움이 되었습니까?

해결책

It is because your window rootViewController is actually a UINavigationController instead of your EmergencyMasterViewController. You need to check how you assign the window root view controller in your app delegate didFinishLaunchingWithOptions or something similar.

Try to get the view controller embedded in the navigation controller, for example:

UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController; 
NSArray *viewControllers = navigationController.viewControllers 
EmergencyMasterViewController *maincontroller = [viewControllers objectAtIndex:0];

It might be safer for the UINavigationController to pop to root view controller first before you try to get the EmergencyMasterViewController, in case the user is already navigating his way through the navigation stack:

[navigationController popToRootViewControllerAnimated:NO];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top