在我的一个 View Controller 中,单击按钮后会调用以下函数,以便我可以进行一些初始化并弹出当前 View (ResultViewController
) 并显示上一个 View (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 上只被调用了一次。
在尝试弄清楚为什么它被调用两次后,我发现第二次调用发生在 GameViewController
的 viewWillAppear
和 viewDidAppear
之间.
知道为什么会发生这种情况吗?
最佳答案
确保检查连接检查器中是否有触发激活 PlayNextList 的事件,特别是如果您有适用于 iPhone 和 iPad 的不同 NIB 文件,并确保该事件不会两次连接到同一方法。
关于objective-c - 为什么我的方法在 iPhone/iPod 上被调用两次,但在 iPad 上却没有?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9416619/