Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS segue executed twice

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.

like image 454
József Vesza Avatar asked Nov 27 '13 01:11

József Vesza


3 Answers

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

like image 89
Mário Carvalho Avatar answered Oct 13 '22 01:10

Mário Carvalho


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.

like image 28
Samman Bikram Thapa Avatar answered Oct 13 '22 00:10

Samman Bikram Thapa


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 :)

like image 38
Matthew Zourelias Avatar answered Oct 13 '22 01:10

Matthew Zourelias