アプリデリゲートがあります。そのデフォルトビューの前にモーダルビューコントローラーがあり、場合によっては2つのモーダルビューコントローラーがあります。そのため、アプリデリゲートでdidFinishLaunchingWithOptions
は、最初のモーダルビューコントローラーが必要かどうかを確認しています。その場合は表示されます。
(を使用して)最初のモーダルビューコントローラーを閉じ[self dismissModalViewControllerAnimated:YES];
たら、2番目のモーダルビューコントローラーを表示したい場合があります。これは、アプリの代理人にも知られています。
したがって、私の解決策はNSNotificationCenter
、最初のモーダルビューコントローラーが却下されたことをアプリデリゲートに通知するために使用することでした。その場合、必要に応じて、アプリデリゲートが2番目のモーダルビューコントローラーを表示できます。
正常に動作しますが、よりクリーンな解決策はありますか?NSNotificationCenter
本当に醜いものだと思います。
複数のモーダルビューコントローラを一度に表示する場合の注意
の中に最初と2番目のモーダルビューコントローラーを表示しようとしましたがdidFinishLaunchingWithOptions
、機能しませんでした。これが私が試したことです:
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window setRootViewController:tabBarController];
[self.window makeKeyAndVisible];
[tabBarController presentModalViewController:pinViewController animated:NO];
if([self needsActivation]) {
[tabBarController presentModalViewController:activationViewController
animated:YES];
}
}
更新:上記のコードは次の修正で機能します:
if([self needsActivation]) {
[pinViewController presentModalViewController:activationViewController
animated:YES];
}