iOS segue执行了两次 [英] iOS segue executed twice

查看:140
本文介绍了iOS segue执行了两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表视图,其中包含不同类型的表视图单元格。在其中一个单元格中,有两个按钮,按下时加载视图控制器。我使用以下功能来处理按钮按下:

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];
}

我的buttonSegue应该推送一个新的视图控制器。不管怎么说,而不是推动一次,它似乎是推了两次,所以我得到以下警告:

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.

在我的情况下,它会导致崩溃,因为有一个事件,我希望该应用程序立即弹出视图控制器,然后返回到我的表视图。我为此使用alertview并使用以下内容处理事件:

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];
    }
}

我可能会感兴趣的是我有另外一个来自我的常规表格视图单元格,在这种情况下我使用prepareForSegue:方法

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];
    }
}

在这种情况下,视图控制器被完美地推送,并且如果需要,甚至立即弹出。我在iOS7和Xcode 5上测试这个。我之前没有遇到过这样的问题,任何帮助都会非常感激。

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.

推荐答案

通过回答poyrazoğlu


您确定已在接口中正确连接了操作
建造者?也许你已经把事件连接起来了,比如说,两个都在
内触摸,然后触摸内部而不是仅仅触摸内部。或者你也可以从
中分配两个代码中的segue,并在界面构建器中再次分配。
你检查过吗?这是一个常见的错误。 -

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. –

我在故事板和tableview的数据源方法中为每个按钮分配了内部操作。

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

感谢您的快速帮助可以poyrazoğlu !!

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

这篇关于iOS segue执行了两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆