【问题标题】:Why is my method being called twice on iPhone/iPod but not on iPad?为什么我的方法在 iPhone/iPod 上被调用了两次,但在 iPad 上却没有?
【发布时间】:2012-02-23 16:02:05
【问题描述】:

在我的一个视图控制器中,单击按钮后会调用以下函数,以便我可以进行一些初始化并弹出当前视图(ResultViewController)并显示上一个视图(GameViewController)。

- (IBAction)PlayNextList:(id)sender {
    NSInteger index = [[[GameStore defaultStore] allLists] indexOfObjectIdenticalTo:[[GameStore defaultStore] selectedList] ];

    if(index == [[[GameStore defaultStore] allLists] count]-1)
    {
        index = 0;
    }
    index++;
    [[GameStore defaultStore] setSelectedList:[[[GameStore defaultStore] allLists] objectAtIndex:index]];
    [[GameStore defaultStore] resetGame]; 

    [[GameStore defaultStore] createResult];
    NSLog(@"Press Next List");
    NSLog(@"%@",[[[[GameStore defaultStore] allLists] objectAtIndex:index] label]);
    [[self navigationController] popViewControllerAnimated:YES];

}

在 iPhone/iPod 上,我注意到 [[GameStore defaultStore] createResult]; 被调用了两次,但在 iPad 上只被调用了一次。

在试图弄清楚为什么它被调用两次后,我发现第二次调用发生在GameViewControllerviewWillAppearviewDidAppear 之间。

知道为什么会这样吗?

【问题讨论】:

  • 在函数中设置断点,当它被命中时,查看回溯。这将为您提供有关两次/一次调用它的反馈。
  • 您是否在此处设置了断点并查看了每个调用的堆栈跟踪?
  • @BP 你能发表你的评论作为答案吗?你是对的。我复制并粘贴另一个按钮来创建按钮,它包括与另一个名为 createResult 的函数的连接,我忘记删除连接。谢谢你!!!昨晚我花了几个小时试图弄清楚这一点。
  • 好的,我将评论作为答案发布并删除了评论。这种情况我也遇到过好几次了,追查起来会很抓狂。很高兴我能帮上忙。

标签: objective-c ios cocoa-touch uinavigationcontroller


【解决方案1】:

确保检查连接检查器是否有触发激活 PlayNextList 的事件,特别是如果您有用于 iPhone 和 iPad 的不同 NIB 文件,并确保该事件没有两次连接到相同的方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-18
    • 1970-01-01
    • 2011-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多