gpt4 book ai didi

ios7 - 使用 Storyboard从 appdelegate 访问 View Controller

转载 作者:行者123 更新时间:2023-12-03 00:50:39 25 4
gpt4 key购买 nike

我已经遵循了 Ray Wendelich 教程 RayWenderlichTutorial Tabbarcontroller using storyboards

只需查看 Storyboard图像即可。Ray 正在使用以下代码访问“playersViewcontroller”

 UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UINavigationController *navigationController = [tabBarController viewControllers][0];
PlayersViewController *playersViewController = [navigationController viewControllers][0];

当我尝试访问playerDetailsViewController时,使用以下代码会崩溃。发送消息

Ratings[2630:60b] * Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]' *** First throw call stack: (0x30b49e83 0x3aea66c7 0x30a7fff9 0x3ddd1 0x3333eaad 0x3333e4f3 0x33338b41 0x332d3a07 0x332d2cfd 0x33338321 0x357b876d 0x357b8357 0x30b14777 0x30b14713 0x30b12edf 0x30a7d471 0x30a7d253 0x333375c3 0x33332845 0x3e0fd 0x3b39fab7) libc++abi.dylib: terminating with uncaught exception of type NSException

代码

UITabBarController *tabBarController =
(UITabBarController *)self.window.rootViewController;
UINavigationController *navigationController =
[[tabBarController viewControllers] objectAtIndex:0];
PlayersViewController *playersViewController =
[[navigationController viewControllers] objectAtIndex:0];

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

我也尝试了下面的代码,

UITabBarController *tabBarController =
(UITabBarController *)self.window.rootViewController;
UINavigationController *navigationController =
[[tabBarController viewControllers] objectAtIndex:0];
PlayersViewController *playersViewController =
[[navigationController viewControllers] objectAtIndex:0];
PlayerDetailsViewController *playerdetailsviewcontroller=[[navigationController viewControllers]objectAtIndex:1];

我在哪里收到消息崩溃

'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'

Storyboard图像 enter image description here

基本上我想从appdelegate访问PlayerdetailsViewcontroller。我想我错过了一些东西,有什么想法吗?

最佳答案

您的应用程序在此处崩溃 (objectAtIndex:1):

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

发生这种情况是因为 naviationController 只有 1 个 subview (PlayersViewController)。如果不通过 Segue 在 PlayersViewController 中实例化 PlayerDetailsViewController,就无法进一步深入 Storyboard。

编辑您只能访问最初可见的 ViewControllers(通过 UITabBarController)。

我也不明白为什么您要向 PlayersViewController 添加另一个 UINavigationController。如果您使用 Segue 将 PlayersViewController 连接到 PlayerDetailViewController,则 navigationController 将被重用(这是正确的方法)。

关于ios7 - 使用 Storyboard从 appdelegate 访问 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21373470/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com