为什么我要在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];
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 presentModalViewController:navigationController animated:YES];
答案 0 :(得分:6)
试试这个:
[self.window.rootViewController presentModalViewController:controller
animated:YES];
答案 1 :(得分:0)
您是否尝试过以下操作?
[self.window.rootViewController.tabBarController.selectedViewController presentModalViewController:navigationController animated:YES];
那就是说,即使这样有效,我也会强烈建议你重新考虑你的设计选择,以避免这样做。以这种方式遍历导航堆栈以访问东西会变得非常混乱,我强烈反对它。