iOS segue executed twice

£可爱£侵袭症+ 提交于 2019-12-03 17:25:07

问题


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.


回答1:


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:

But you should wire them with the view controllers instead:




回答2:


Answer by 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!!




回答3:


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.




回答4:


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



来源:https://stackoverflow.com/questions/20231145/ios-segue-executed-twice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!