选择最初将显示的ViewController

时间:2014-07-11 23:56:40

标签: ios uiviewcontroller nsuserdefaults

我试图选择AppDelegate应该基于NSUserDefaults BOOL显示哪个ViewController。但是HomeViewController没有显示。 我使用的是故事板,我有自己的UINavigationController类。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    [FBLoginView class];
    [FBProfilePictureView class];

    MeuNavigationController *nav = [[MeuNavigationController alloc]init];
    if ([NSUD boolForChave:@"firstLogin"]==false) {
        ViewController *viewC = [[ViewController alloc]init];
        [nav pushViewController:viewC animated:NO];
    }else{
        HomeViewController *viewP = [[HomeViewController alloc]init];
        [nav pushViewController:viewP animated:NO];
    }

    return YES;
}

1 个答案:

答案 0 :(得分:2)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    [FBLoginView class];
    [FBProfilePictureView class];

    UIViewController *controller = nil;
    if ([NSUD boolForChave:@"firstLogin"]==false) {
        controller = [[ViewController alloc]init];
    }else{
        controller = [[HomeViewController alloc]init];
    }
    self.window.rootViewController = [[MenuNavigationController alloc] initWithRootViewController:controller];
    [self.window makeKeyAndVisible];

    return YES;
}

你注意到你是在故事板上做的。您可能还想考虑进行此更改:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    [FBLoginView class];
    [FBProfilePictureView class];

                                                                // Name of storyboard
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

    UIViewController *controller = nil;
    if ([NSUD boolForChave:@"firstLogin"]==false) {
        controller = [[ViewController alloc]init];
                                                                        // Set this in the storyboard's identity inspector
        controller = [storyboard instantiateViewControllerWithIdentifier:@"ViewController"];
    }else{
        controller = [storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];
    }
    self.window.rootViewController = [[MenuNavigationController alloc] initWithRootViewController:controller];
    [self.window makeKeyAndVisible];

    return YES;
}

但是你问...... jakenberg先生,如何设置他们独特的视图控制器标识符?

enter image description here

干杯