gpt4 book ai didi

ios - 以编程方式初始化导航 Controller 堆栈

转载 作者:行者123 更新时间:2023-11-29 04:00:14 24 4
gpt4 key购买 nike

这是按下按钮的代码:

- (IBAction)newPoint:(id)sender {
[self.tabBarController setSelectedIndex:1];

UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"navid"];
UIViewController *tblvc = [self.storyboard instantiateViewControllerWithIdentifier:@"tblid"];

UINavigationController *nvc1 = self.tabBarController.viewControllers[1];
[nvc1 pushViewController:tblvc animated:NO];
[nvc1 pushViewController:vc animated:NO];
}

这是我的 Storyboard enter image description here

这是我得到的异常:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported'

我想要实现的是在点击按钮时显示最右边的 View Controller (在 Storyboard中)。然后我希望导航 Controller 的后退按钮转到 Root View Controller ,就像我手动到达该 Controller 一样。

为此,我更改为第二个选项卡(因为按钮位于第一个选项卡上),然后尝试初始化导航 Controller 。但我可能缺少一些东西......

最佳答案

确保您在 Storyboard内的正确 View Controller 上设置了 Storyboard ID。对我来说,它看起来像是

UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"navid"];

或者

UIViewController *tblvc = [self.storyboard instantiateViewControllerWithIdentifier:@"tblid"];

正在创建 UINavigation Controller 的新实例。您可以使用以下内容来确认这一点

    - (IBAction)newPoint:(id)sender {
[self.tabBarController setSelectedIndex:1];

UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"navid"];
UIViewController *tblvc = [self.storyboard instantiateViewControllerWithIdentifier:@"tblid"];

NSLog(@"vc - %@",NSStringFromClass([vc class]));
NSLog(@"tblvc - %@",NSStringFromClass([tblvc class]));

UINavigationController *nvc1 = self.tabBarController.viewControllers[1];
[nvc1 pushViewController:tblvc animated:NO];
[nvc1 pushViewController:vc animated:NO];
}

然后在调试器中检查类名。 UINavigationController (或子类)中的任何一个都是问题所在。

关于ios - 以编程方式初始化导航 Controller 堆栈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15957881/

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