我正在制作一个包含多个标签视图的iOS应用。其中两个视图使用相同的视图控制器,因此它们都有一个实例。我想知道两个视图是否只能使用一个视图控制器实例。我想这样做的原因是因为我在一个使用GameKit对等选择器的视图上有一个“连接”和“断开连接”按钮,我在另一个视图上有“发送文件”,该视图必须使用我从使用连接按钮的其他视图。
答案 0 :(得分:0)
在任何属于tabBarController的viewController中:
UIViewController *vc1 = [self.tabBarController.viewControllers objectAtIndex:0];
MyCustomClass *sharedObject = [vc1 theObject];
UIViewController *vc2 = [self.tabBarController.viewControllers objectAtIndex:1];
[vc2 setTheObject:sharedObject];
您应该为两个视图控制器的“theObject”设置@property