Access a view controller from appdelegate using storyboard

 ̄綄美尐妖づ 提交于 2019-12-03 20:25:47

Your app crashes here (objectAtIndex:1):

UINavigationController *nav = [[navigationController viewControllers] objectAtIndex:1];
PlayerDetailsViewController *playerdetailsviewcontroller = [[nav viewControllers]objectAtIndex:0];

This happens because naviationController has only 1 subview (PlayersViewController). You can't go further down the storyboard without instantiating the PlayerDetailsViewController within PlayersViewController via a Segue.

EDIT You can only access the ViewControllers that are initially visible (via the UITabBarController).

I also don't get why you're adding another UINavigationController to the PlayersViewController. If you connect PlayersViewController to PlayerDetailViewController with a Segue the navigationController will be reused (this would be the correct way to do so).

It looks like you have a modal segue from Players to Player Details. So you could use the presentedViewController property of PlayersViewController, something like this

PlayersViewController *playersViewController = [navigationController.viewControllers firstObject];
UINavigationController *secondNavigationController = playersViewController.presentedViewController;
PlayerDetailsViewController *playerDetailsViewController = [secondNavigationController.viewControllers firstObject];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!