我的模特一团糟吗?
我正在编写一个包含多个视图的iPad应用。我有一个masterViewController,可以查看其他视图控制器。其中一些子视图包含按钮。
用户单击这些按钮可更改视图。我的意图是masterViewController负责更改这些视图。但是如何?
当按下按钮时,masterViewController如何判断?
@implementation subViewControllerOne
- (IBAction) switchToSubViewTwo {
//Where to I send my message?
[masterViewController myMethod] //doesn't work because I need to message the specific instance
}
答案 0 :(得分:2)
你可以
答案 1 :(得分:0)
您可能希望通过AppDelegate查找对控制器的引用。
确保在AppDelegate中为masterViewController
添加插座并连接它(使用Interface Builder)。然后,在子视图的控制器中,获取对AppDelegate的引用并运行您的方法,如下所示:
MyAppDelegate *delegate = (MyAppDelegate *)[UIApplication sharedApplication].delegate;
[delegate myMethod];