我正在尝试在使用 Storyboard的应用程序中访问 View Controller 中的数组变量。
背景:
我一直在关注 Ray Wenderlich tutorial on Storyboards .
完成本教程后,我返回尝试了不同的路线,但我在访问 View Controller 时遇到了问题。一切都几乎相同,除了我的设置是初始场景是一个 View Controller 。我到了作者在他的表中向 NSMutableArray 添加一些数据的部分。
我用作指南的他们的代码
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UINavigationController *navigationController = [tabBarController viewControllers][0];
PlayersViewController *playersViewController = [navigationController viewControllers][0];
playersViewController.players = _players;
我希望它会像复制我在 View Controller 中看到的那样简单,传递适当的类型,但是没有。
我有 View Controller > View Controller > Navigation View Controller > UITableViewController。
我的代码:
UIViewController *vc = (UIViewController*)self.window.rootViewController;
UIViewController vc1 = [vc viewController][0];
UINavigationController *nc = [vc1 viewController][0];
SearchViewTableViewController *svc = [nc viewControllers][0];
svc.myarray = _myarray;
我尝试了多种组合,但一无所获。
必须有一种更简单的方法来引用类/ View /场景。 有帮助吗?
最佳答案
确保您正在导入 ViewController 头文件。
确保您已为 ViewController 提供了 Storyboard 标识符。
然后像这样的东西应该工作:
MyViewController *myVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"MyViewController"];
myVC.myMutableArray = [NSMutableArray new];
....
关于ios - 从 AppDelegate 问题访问 Storyboard ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27892900/