2012-02-29 5 views
3

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]; 

}

更新

これがnilであるようです: self.window.rootViewController.tabBarController.selectedViewController.navigationController

Solution

[self.window.rootViewController presentModalViewController:navigationController animated:YES];

+0

self.window.rootViewController.tabBarController.selectedViewController.navigationController == nilを? – NeverBe

+0

ありがとうございます。はい、ちょうどテストされ、実際にはゼロです。なぜそれがうまくいかなかったのだろうか。しかし、なぜそれは無しで、どこからここに行くのですか? – Pieter

+0

[self.window.rootViewController presentModalViewController:navigationController animated:YES]; – NeverBe

答えて

6

これを試してみてください:

[self.window.rootViewController presentModalViewController:controller 
                animated:YES]; 
+0

ありがとうございます –

0

あなたは次のことを試しましたか?

[self.window.rootViewController.tabBarController.selectedViewController presentModalViewController:navigationController animated:YES]; 

しかし、これが機能しても、私はあなたにこれをやらなければならないことを避けるためにデザインの選択肢を再検討するよう強くお勧めします。物事にアクセスするためにこのような方法でナビゲーションスタックを横断すると、非常に乱雑になる可能性があります。私はそれに対して強くアドバイスします。

+0

同じこと、動作しません。ビューはロードされません(ViewDidLoadは呼び出されません)。 – Pieter

+0

他の開発者が通知を処理するためのモーダルビューをどのように表示しているのかよくわかりません。言い換えれば、私は別の方法でこれをどうやってやるのかという手がかりはない。 – Pieter

+0

適切なView Controller上でメソッドを呼び出すと、表示されている場合はpresentModalViewControllerを呼び出します。 –

関連する問題