jimbob
jimbob

Reputation: 3298

Segue will not load using performSegueWithIdentifier

I have given my segue the identity modaltomenu

modaltomenu

in my code I am calling the segue with the following:

if([login_status isEqualToString:@"success"]){
            //start the menuviewcontroller
            [self performSegueWithIdentifier:@"modaltomenu" sender:self];

            NSLog(@"segue %@", @"performed");
        }

the if statement is always true.

However the second view is never loaded. This code is ran when the first view loads.

Why isnt my segue loading?

Thanks!

Upvotes: 0

Views: 5366

Answers (2)

user1349234
user1349234

Reputation:

You said the code is ran when the first view loads so am I right in assuming its in the viewDidLoad method? If so, try moving that if statement to the viewDidAppear method in the view controller life cycle. ViewDidLoad usually only happens once, whereas viewDidAppear is called every time the view appears on screen. So it would look like...

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:YES];
    if([login_status isEqualToString:@"success"]){
        //start the menuviewcontroller
        [self performSegueWithIdentifier:@"modaltomenu" sender:self];

        NSLog(@"segue %@", @"performed");
    }
}

Upvotes: 1

LJ Wilson
LJ Wilson

Reputation: 14427

To troubleshoot further, put this in that VC:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    NSLog(@"segue identififer = %@",segue.identifier);
}

And make sure that your code in viewDidLoad is executing as expected. If it doesn't, you might want to re-think where you call that performSegue method.

Upvotes: 1

Related Questions