为什么要在AppDelegate中使用presentModalViewController?
-处理didReceiveLocalNotification,因此我可以在我的应用程序顶部启动一个单独的modalView来处理通知
我的视图架构是什么样的?
-使用故事板
-MainStoryBoard:-> TabBarController-> NavigationController
发生了什么?
-没关系,这就是问题:-D
-当我按下UILocalNotification中的操作按钮时,该应用程序将打开,但仅显示tabbarcontroller中的最后一个打开的视图。
正如您在下面看到的,我最后的努力是在当前视图之上显示modalViewController,如下所示:[self.window.rootViewController.tabBarController.selectedViewController.navigationController presentModalViewController:navigationController animated:YES];
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateInactive) {
// Application was in the background when notification was delivered.
NSLog(@"Received notification while in the background");
}
else {
NSLog(@"Received notification while running.");
}
MedicationReminderViewController *controller = [[UIStoryboard storyboardWithName:@"ModalStoryBoard" bundle:nil] instantiateViewControllerWithIdentifier:@"MedicationReminderVC"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
[self.window.rootViewController.tabBarController.selectedViewController.navigationController presentModalViewController:navigationController animated:YES];
}
更新
似乎这是零:self.window.rootViewController.tabBarController.selectedViewController.navigationController
解决方案
[self.window.rootViewController presentModalViewController:navigationController动画:是];
最佳答案
试试这个 :
[self.window.rootViewController presentModalViewController:controller
animated:YES];
关于ios - 为什么我的presentModalViewController无法从AppDelegate内部工作?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9500537/