embed in --> navigation controller"嵌入导航 Controller-6ren"> embed in --> navigation controller"嵌入导航 Controller-我在 appDelegate.m 中通过代码创建标签栏 Controller 并将标签栏 Controller 设置为 rootViewController。因此,在 main.storyboard -6ren">
gpt4 book ai didi

ios - 通过 appDelegate.m 中的代码而不是 "Menu:Editor --> embed in --> navigation controller"嵌入导航 Controller

转载 作者:行者123 更新时间:2023-11-29 02:21:27 26 4
gpt4 key购买 nike

我在 appDelegate.m 中通过代码创建标签栏 Controller 并将标签栏 Controller 设置为 rootViewController。因此,在 main.storyboard 中我没有指向导航 Controller 的指针,我想通过代码为 tabbarcontronller 设置导航 Controller ,我怎样才能做到这一点?如果我不设置导航 Controller ,它会抛出异常“'Push segues can only be used when the source controller is managed by a instance of UINavigationController.'”

NSArray *titleList = @[@"Bán chạy",@"Mới nhất",@"Lịch sử",@"Khách hàng"];
NSArray *imageList = @[@"icon_hot_normal.png",@"icon_new_normal.png",@"icon_history_normal.png",@"icon_user_normal.png"];

NSArray *viewCtrIdentifierList = @[@"best_sale_id",@"history_id"];

UITabBarController *tabbarCtr = [[UITabBarController alloc]init];

self.window.rootViewController = tabbarCtr;
[tabbarCtr navigationController];
NSMutableArray *tabbarList = [[NSMutableArray alloc]init];
for (int i=0; i < viewCtrIdentifierList.count; i++) {
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

UIViewController *viewCtr = [storyBoard instantiateViewControllerWithIdentifier:viewCtrIdentifierList[i]];
[tabbarList addObject:viewCtr];
}

tabbarCtr.viewControllers = tabbarList;
int i=0;
for (UITabBarItem *item in tabbarCtr.tabBar.items) {
item.title = titleList[i];
item.image = [UIImage imageNamed:imageList[i]];
i++;
}

最佳答案

这段代码应该是您走上正轨所需要的。

基本上,您需要将每个选项卡的 Root View Controller 包装在 UINavigationController 中。你们非常亲密。

此代码应该可以解决您的问题:

NSArray *viewCtrIdentifierList  = @[@"best_sale_id",@"history_id"];
UITabBarController *tabbarCtr = [[UITabBarController alloc] init];
self.window.rootViewController = tabbarCtr;
NSMutableArray *tabbarList = [[NSMutableArray alloc]init];
for (int i=0; i < viewCtrIdentifierList.count; i++) {
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *viewCtr = [storyBoard instantiateViewControllerWithIdentifier:viewCtrIdentifierList[i]];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewCtr];
[tabbarList addObject:nav];
}
tabbarCtr.viewControllers = tabbarList;

关于ios - 通过 appDelegate.m 中的代码而不是 "Menu:Editor --> embed in --> navigation controller"嵌入导航 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28085453/

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