标题说明了我要找的大部分内容:
我的主菜单上有 2 个按钮,它们都调用同一个 View Controller 。根据单击哪个按钮, View Controller 的行为会有所不同。我以为我已经使用 NSNotificationCenter 进行了修复,但它不会在第一次进入 View Controller 时捕获任何内容(因为它尚未加载)。还有其他方法可以做到这一点吗?
编辑:似乎有些困惑,也许在我这边。问题是跨多个 View Controller 传递信息。主菜单 View Controller 中的按钮调用第二个 View Controller ,问题是第二个 View Controller 不知道在主菜单 View Controller 中创建的任何变量。
最佳答案
您可以向第二个 View Controller 的类添加一个变量,并将该变量设置为一个值,具体取决于初始化第二个 View Controller 时按下的按钮:
- (IBAction) buttonPressed:(id)button
{
//Initialize your view controller
MyViewController* secondViewController = [[MyViewController alloc] init...];
//Assign a value to a variable you create (I called it pushedButtonValue) so the
//viewController knows which button was pressed
secondViewController.pushedButtonValue = [button tag];
//Transition to the new view controller
[self.navigationController pushViewController:secondViewController animated:YES];
}
关于objective-c - iOS : 2 Buttons both call the same view controller. 如何找到点击的是哪一个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6916169/