iOS segue ejecutado dos veces

I have a table view with different types of table view cells in it. In one of the cells, there are two buttons, which load a view controller when pressed. I am using the following function to handle the button press:

- (IBAction)leftButtonPressed:(id)sender
{
    // Getting the pressed button
    UIButton *button = (UIButton*)sender;
    // Getting the indexpath
    NSIndexPath *indPath = [NSIndexPath indexPathForRow:button.tag inSection:0];
    // Loading the proper data from my datasource
    NSArray *clickedEvent = [[[SOEventManager sharedEventManager] eventsArray] objectAtIndex:indPath.row];
    [[SOEventManager sharedEventManager] setSelectedEvent:clickedEvent[0]];
    // Everything working as it should up to this point
    // Performing seque...
    [self performSegueWithIdentifier:@"buttonSegue" sender:self];
}

My buttonSegue is supposed to push a new view controller. Somehow instead of pushing once, it appears to be pushing twice, so I get the following warning:

2013-11-27 01:48:30.894 Self-Ordering App[2081:70b] nested push animation can result in corrupted navigation bar 
2013-11-27 01:48:31.570 Self-Ordering App[2081:70b] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.

In my case it leads to a crash, since there is an event in which I want the app to immediately pop the view controller so it an go back to my table view. I use an alertview for this and handle the event with the following:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSString *buttonTitle = [alertView buttonTitleAtIndex:buttonIndex];
    // ...
    // Additional checking of button titles....
    else if ([buttonTitle isEqualToString:NSLocalizedString(@"Vissza", nil)])
    {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

It might me interesting to note that I have an other segue from my "regular" table view cell, and in that case I use the prepareForSegue: method

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"detailSegue"])
    {
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        SOEvent *selectedEvent = [[[SOEventManager sharedEventManager] eventsArray] objectAtIndex:indexPath.row];
        [[SOEventManager sharedEventManager] setSelectedEvent:selectedEvent];
    }
}

In this case the view controller gets pushed perfectly, and even popped immediately if that is required. I am testing this on iOS7 and Xcode 5. I haven't encountered a problem like this before, any help would be greatly appreciated.

preguntado el 27 de noviembre de 13 a las 01:11

are you sure you've wired up the actions correctly in interface builder? maybe you've wired the event for, say, both touch up inside and touch down inside instead of just touch up inside. or maybe you've also assigned the segue from both code and again in interface builder. have you checked them? it's a common mistake. -

Oh damn.. You are actually right, I assign my buttons also in the table view datasource methods.. Thank you for your answer! -

4 Respuestas

Maybe you want to wire up your segues with View Controllers instead of UIButtons!

You should probably have the segues wired with some button like this: enter image description here

But you should wire them with the view controllers instead: enter image description here

Respondido el 07 de junio de 15 a las 01:06

This worked for me! (Swift 4, Xcode 9). Not sure why this is not emphasized more! Using a delegate, if the segue was wired between a button (in a table cell), it would always fire, and my delegate would be executed afterward. Wired to the cell view, this does not happen, so my manual call to do the segue works as planned. - davidg

Respuesta por can poyrazoğlu:

are you sure you've wired up the actions correctly in interface builder? maybe you've wired the event for, say, both touch up inside and touch down inside instead of just touch up inside. or maybe you've also assigned the segue from both code and again in interface builder. have you checked them? it's a common mistake. –

I was assigning the touch up inside actions for each button both the storyboard and my tableview's datasource methods.

Thank you for your quick help can poyrazoğlu!!

respondido 27 nov., 13:01

oh, I didn't really think about table view, but glad to see it helped. you are welcome :) - Can Poyrazoğlu

I was loading the new view controller 2x also. I connected the segue from the view controller instead of the tableview cell and this solved the problem. - jeffk

For Swift 3, xcode, and ios 9+, which is what I am using: Make sure you are drawing segue from your UIViewControllers and not buttons or other interfaces.

I had the same problem, and simply changing the start of the segue from the UIController instead of the button removed this bug.

respondido 07 mar '17, 01:03

I always get this issue when I have my buttons directly wired up to the destination view controller. You need to make sure that you first delete the old segue you made, then click on the present view controller (where you are coming from) and CTRL + click to destination controller.

This should fix it :)

Respondido 24 Feb 17, 15:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.