爲什麼我想在AppDelegate中使用presentModalViewController? - 正在處理didReceiveLocalNotification,所以我可以在我的應用程序頂部啓動一個單獨的modalView來處理通知爲什麼我的presentModalViewController無法在AppDelegate中工作?
我的視圖體系結構是什麼樣子的? - 使用故事板 - 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 animated:YES];
self.window.rootViewController.tabBarController.selectedViewController.navigationController ==零? – NeverBe 2012-02-29 14:34:35
謝謝。該死的,剛剛測試過,實際上是零。難怪爲什麼它不起作用。但爲什麼它是零,我從哪裏去? – Pieter 2012-02-29 14:42:05
[self.window.rootViewController presentModalViewController:navigationController animated:YES]; – NeverBe 2012-02-29 14:48:04