アプリを初めて開いたときに、アプリの使用方法の説明が表示されるビューが欲しいのですが。NSUserDefaultsを使用して、最初の起動時にこのビューのみを表示するという問題を処理しましたが、rootViewControllerとしてではなく、モーダルで表示したい方法でビューを表示するのに問題があります。これが私のAppDelegate.mコードです:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
BOOL hasShownStartup = [[NSUserDefaults standardUserDefaults] boolForKey:kAppHasShownStartupScreen];
if (!hasShownStartup) {
[self showInstructions];
}
[self.window makeKeyAndVisible];
return YES;
}
- (void)showInstructions
{
NSLog(@"showing instructions");
InstructionsViewController *howToView = [[InstructionsViewController alloc] initWithNibName:@"InstructionsViewController"
bundle:nil];
self.instructionsViewController = howToView;
[howToView release];
UINavigationController *howtoNavController = [[UINavigationController alloc]
initWithRootViewController:self.instructionsViewController];
self.instructionsViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.viewController presentModalViewController:howtoNavController animated:NO];
[howtoNavController release];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:kAppHasShownStartupScreen];
}
rootViewControllerをself.viewControllerのままにしておきたい。InstructionsViewControllerナビゲーションバーの[完了]をクリックして、rootViewControllerに戻ることができるようにしたいと思います。記述されたとおりにコードを実行しても、命令ビューは表示されません。私がinstructionsViewControllerを見ることができる唯一の方法は、行[self.viewController presentModalViewController:howtoNavController animated:NO];
をに変更する場合ですself.window.rootViewController = self.instructionsViewController;
が、これは明らかに私が望むものではありません(モーダルでviewControllerに戻ることができない限り)。
うまくいけば、私が達成しようとしていることを十分に明確にした。前もって感謝します。