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。我希望能够单击指令视图控制器导航栏上的“完成”以转换回 rootViewController。执行编写的代码永远不会显示指令视图。我可以看到指令ViewController 的唯一方法是如果我将行更改[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]after [self.window makeKeyAndVisible]

[self.window makeKeyAndVisible];

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