ios - 从 AppDelegate 向 ViewController 的属性添加值

标签 ios objective-c uiviewcontroller appdelegate

我有以下代码:

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/

相关文章:

ios - 每次显示 View 时运行方法 - iOS

ios - 覆盖本地化字符串的 NSManagedObject getter

ios - 将 xib 文件作为 UITableViewController 中的 header 添加到 UITableView

ios - 推送通知不显示

iphone - 以编程方式更改按钮状态

ios - 检测哪个特定的 map 图钉被触摸

iphone - 适用于 iPhone 的类似 Web 的选项卡

ios - Swiftycam 媒体捕获库委托(delegate)崩溃

ios - 在 UITableViewController 上使用 UIViewController 类

ios - 如何使用 Parse (swift) 邀请用户加入多人游戏 session