nick
nick

Reputation: 2853

Segue not being performed ios

I've got an iOS app that allows a user to connect to our server and perform a couple tasks. It works great until I decided to throw an error in and make it go back to the previous view controller. I created a segue with the Identifier of "segShowError" that is supposed to be executed and send the user back to the parent screen. Currently the segue is a Modal, as is the one that goes from the first controller to the second one. The odd part is I was experiencing this same difficulty earlier when I was using a push segue and I fixed it by using a Modal instead. Here is the code that "should" be performing the segue.

NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if(error != nil)
{
    NSLog(@"Error was %@",error);
    return;
}
else if([data length] <= 0)
{
    NSLog(@"No data received, going back");
    [self performSegueWithIdentifier:@"segShowError" sender:self];
}

And then I have a prepareForSegue method, it will determine what error message to send back to the parent, but right now just logs a message.

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSLog(@"Preparing for segue");
}

My output

2012-03-21 13:14:39.148 SSPColorImprov[17401:f803] No data received, going back

2012-03-21 13:14:39.149 SSPColorImprov[17401:f803] Preparing for segue

I would think that those two messages would indicate that the segue is being performed, but I could be wrong.

There are no errors logged, no warnings in the project, and no exceptions thrown. Any ideas what might be causing the problem?

Upvotes: 0

Views: 490

Answers (1)

Sierra Alpha
Sierra Alpha

Reputation: 3727

To dismiss a view that is presented modally, you need to dismiss it by calling - dismissViewControllerAnimated:completion: rather than using segues. e.g.

// used to be dismissModalViewControllerAnimated: but deprecated in iOS 5
[self dismissViewControllerAnimated:YES completion:nil];

Upvotes: 3

Related Questions