0

我想在我的应用程序第一次启动时显示导览。

我肯定会用一些NSUserDefaults。但是我正在使用storyboards并且我想加载不同viewControllers的加载。

if(firstTime)
Load TourController 
else
Load mainScreen

我怎样才能实现这个appdelegate

4

2 回答 2

1

我的应用程序第一次启动时有不同的行为,但我没有在应用程序委托中实现它。我在委托中使用代码来跟踪启动次数。然后,由于主视图控制器需要位于视图树的顶部,因此我从那里以模态方式推送了第一个启动行为。

- (void)applicationDidBecomeActive:(UIApplication *)application {

    // the following forces new behaviour on 1st launch. 
    int launches;
    launches = [[NSUserDefaults standardUserDefaults] integerForKey:LAUNCH_NUMBER_KEY];
    // note: uninitialised user default returns 0.

    if (!launches) {
        // view did load will check again and push the first load tour. 
        // by returning here, the launch value is not incremented. 
        [self.viewController viewDidLoad];
        return;
    } 
}       

然后,在 中MainViewController viewDidLoad,我再次检查该值并以模态方式推送 firstLoad 视图。

- (void)viewDidLoad {
    //... more code here.
    BOOL disclaimerAccepted = [[NSUserDefaults standardUserDefaults] boolForKey:DISCLAIMER_ACCEPT_KEY];
    if (!disclaimerAccepted) {
    [self showFirstLoadView];
    return;
    }
}

-(void) showDisclaimerView {

    // Display the nav controller modally.
    FirstLoadVC *firstLoadVC = [[FirstLoadVC alloc] initWithNibName:@"firstload" bundle:[NSBundle mainBundle]];
    [firstLoadVC autorelease];

    UINavigationController*  firstLoadNavController = [[UINavigationController alloc]initWithRootViewController:firstLoadVC]; 

    [self presentModalViewController:firstLoadNavController animated:YES];

    [firstLoadNavController release];
}
于 2012-09-01T07:57:25.373 回答
1
if (firstTime) {
   self.window.rootViewController = self.fisrtController; 
} else {
   self.window.rootViewController = self.mainController;
}
于 2012-09-01T07:31:10.073 回答