2012-02-15 20 views
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)。

希望我已经明确了我想要完成的事情。提前致谢。

回答

2

尝试将[self showInstructions];改为applicationDidBecomeActive:

+0

哇。非常感谢。我不认为我会这么想。 – 2012-02-15 21:04:30

0

尝试把[self showInstructions][self.window makeKeyAndVisible]

[self.window makeKeyAndVisible]; 

if (!hasShownStartup) { 
    [self showInstructions]; 
} 
相关问题