我有以下代码:
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
[tabBarController performSegueWithIdentifier:@"push_display_incomming_call" sender:self];
这向我展示了我想要正确查看的 ViewController。但是现在我想在显示之前更改 ViewController 的属性值正在 Segue,我正在尝试以下操作但没有成功。
incommingCallViewController *mainController = (incommingCallViewController*) tabBarController;
mainController.name.text = @"Eddwn Paz";
这是来自 xCode 控制台的堆栈跟踪:
2014-07-10 16:46:09.413 mobile-app[9354:60b] -[OptionsTabBarViewController name]: unrecognized selector sent to instance 0x17552540
2014-07-10 16:46:09.414 mobile-app[9354:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[OptionsTabBarViewController name]: unrecognized selector sent to instance 0x17552540'
最佳答案
假设 push_display_incomming_call
segue 将 IncommingCallViewController
View Controller 呈现为模态。所以你应该使用代码:
IncommingCallViewController *callVC =
(IncommingCallViewController *)tabBarController.presentedViewController;
callVC.name.text = @"Eddwn Paz";
备注:
您收到错误是因为您尝试将 tabBarController
用作 incommingCallViewController
的实例,而它是 UITabBarController
的实例,因此它不需要名称
属性。
关于ios - 从 AppDelegate 向 ViewController 的属性添加值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24686549/