0

I use Xcode 6. I have several view controllers connecting together with present Seques(push). I set the initial point to navigation controller. My app loads with view or table view controller based on one circumstance. I embedded in Navigation controller using the editor menu. I can see the navigation controller before running, but it disappear in run time. Does any one know the reason?

I am suspicious to this part of my code in applicationdidfinishlaunchwithoption cause this problem:

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSInteger RegisteredFlagNumber = [defaults integerForKey:@"RegisteredFlag"];
    bool isLoggedIn= (RegisteredFlagNumber==1) ? true:false;
    NSString *storyboardId = isLoggedIn ? @"MainIdentifier" : @"LoginIdentifier";
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *initViewController = [storyboard instantiateViewControllerWithIdentifier:storyboardId];
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = initViewController;
    [self.window makeKeyAndVisible];

but I do not know how to fix it?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Mina
  • 85
  • 1
  • 9

2 Answers2

0

You need to set it as Initial ViewController at IB.

In the attributes inspector look for the View Controller or Window Controller category and set the Is Initial View Controller checkbox.

https://developer.apple.com/library/ios/recipes/xcode_help-IB_storyboard/chapters/SetInitialController.html

Klevison
  • 3,342
  • 2
  • 19
  • 32
0

I found the answer: I add it programatically in applicationdidfinishluchwithoption:

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSInteger RegisteredFlagNumber = [defaults integerForKey:@"RegisteredFlag"];
    bool isLoggedIn= (RegisteredFlagNumber==1) ? true:false;
    NSString *storyboardId = isLoggedIn ? @"MainIdentifier" : @"LoginIdentifier";
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

//here it is the changes for getting result

  UIViewController *initViewController = [storyboard instantiateViewControllerWithIdentifier:storyboardId];
    UINavigationController *navigationController=[[UINavigationController alloc]initWithRootViewController:initViewController];



  self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

//here it is the changes for getting result

    self.window.rootViewController = navigationController;
    [self.window makeKeyAndVisible];
Mina
  • 85
  • 1
  • 9