0

アプリを初めて開いたときに、アプリの使用方法の説明が表示されるビューが欲しいのですが。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に戻ることができない限り)。

うまくいけば、私が達成しようとしていることを十分に明確にした。前もって感謝します。

4

2 に答える 2

2

代わりに移動[self showInstructions];してみてください。applicationDidBecomeActive:

于 2012-02-15T20:59:26.803 に答える
0

[self showInstructions]後に入れてみてください[self.window makeKeyAndVisible]

[self.window makeKeyAndVisible];

if (!hasShownStartup) {
    [self showInstructions];
}
于 2012-02-15T21:06:39.967 に答える