0

I have a storyboard with a UINavigationController. The root view controller of the navigation controllers is called rootViewController.

I am trying to programmatically change the view controller (depending on other conditions) to another view controller called loginViewController.

I am trying to do this in the viewDidLoad from the rootViewController like this:

- (void)viewDidLoad
{

    [super viewDidLoad];

    loginViewController *viewController = [[loginViewController alloc] init];

    [self.navigationController pushViewController:viewController animated:YES];

}

I am not getting any errors but it's not working.

It just loads the navigation controller with the top nav back button but the rest of the screen is black. It's like it's not loading any view controller.

I am trying to figure out what I am doing wrong.

Any help with this would be great.

Thanks

3
  • Did you add your viewController with UINavigationController in AppDelegate? like that UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:self.viewController]; Commented Feb 26, 2013 at 9:15
  • How is the loginViewControllers view initialized? With a xib? In code? From a storyboard? Sounds to me like you're pushing a ViewController without a view. Commented Feb 26, 2013 at 9:17
  • why are you pushing the viewcontroller in viewdidload? Commented Feb 26, 2013 at 9:22

2 Answers 2

5

First add loginViewController class in storyboard and and connect ViewController class to loginViewController class and give identifier name as "identifier_Name".

- (void)viewDidLoad
{

    [super viewDidLoad];
    [self performSegueWithIdentifier:@"identifier_Name" sender:nil];
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if([[segue identifier] isEqualToString:@"identifier_Name"])
    {
        loginViewController *viewController = [segue destinationViewController];
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

If you're using storyboard, create your login view in the storyboard, link your rootVC to the loginVC with a segue, choose an identifier (for example: "goToLogin"). and then to go in the login view, and use:

[self performSegueWithIdentifier:@"goToLogin" sender:self];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.