我有以下代码:
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 Console的stacktrace:
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
视图控制器呈现为模态。所以你应该使用代码:
IncommingCallViewController *callVC =
(IncommingCallViewController *)tabBarController.presentedViewController;
callVC.name.text = @"Eddwn Paz";
备注:
收到错误是因为尝试将
tabBarController
用作incommingCallViewController
的实例,而它却是UITabBarController
的实例,因此它没有必需的name
属性。