Sequenzia
Sequenzia

Reputation: 2381

iOS navigationController pushViewController not working

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

Upvotes: 0

Views: 3604

Answers (2)

Prasad G
Prasad G

Reputation: 6718

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];
    }
}

Upvotes: 5

Jeremy
Jeremy

Reputation: 1521

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];

Upvotes: 0

Related Questions