我正在尝试在收到远程通知时从App委托方法更改为主视图,以便在主视图中执行segue到另一个视图,但我收到NSInvalidArgumentException
当didReceiveRemoteNotification:时,App Delegate中的代码
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
EmergencyMasterViewController* maincontroller = (EmergencyMasterViewController*)self.window.rootViewController;
[maincontroller alert];
}
MasterView中的代码:
-(void)alert
{
[self performSegueWithIdentifier: @"Warning" sender: self];
}
我得到的错误:[UINavigationController alert]: unrecognized selector
答案 0 :(得分:1)
这是因为你的窗口rootViewController实际上是一个UINavigationController,而不是你的EmergencyMasterViewController。您需要检查如何在app delegate didFinishLaunchingWithOptions或类似内容中分配窗口根视图控制器。
尝试将视图控制器嵌入导航控制器中,例如:
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
NSArray *viewControllers = navigationController.viewControllers
EmergencyMasterViewController *maincontroller = [viewControllers objectAtIndex:0];
在您尝试获取EmergencyMasterViewController之前,UINavigationController首先弹出到根视图控制器可能更安全,以防用户已经在导航堆栈中导航:
[navigationController popToRootViewControllerAnimated:NO];