我想在我当前的 App Flow 中添加一个标签栏控制器。目前我有一个带有按钮的页面,单击该按钮会打开一个新的视图控制器,其中包含用户登录的 Web 视图,登录后我想带他到他的主页,其中导航栏有他的名字和右侧的注销按钮. 主页还应该有一个带有 3 个不同选项卡的选项卡栏。我能够从 webview 加载主页视图并获取导航栏。但我无法添加 tabBar 并让它工作。我对在哪里添加用于添加 TabBar 的代码感到困惑。我正在使用以下代码添加标签栏 -
UITabBarController *tabBar = [[UITabBarController alloc] init];
HomeViewController *home = [[PPHomeViewController alloc] initWithUserName:[self.userInfo objectForKey:@"name"] Email:[self.userInfo objectForKey:@"email"] Phone:[self.userInfo objectForKey:@"phone_number"]];
home.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:1];
UINavigationController *homeNavController = [[UINavigationController alloc]initWithRootViewController:home];
RequestViewController *req = [[RequestMoneyViewController alloc]init];
req.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:2];
UINavigationController *reqNavController = [[UINavigationController alloc]initWithRootViewController:req];
UIViewController *thirdViewController = [[UIViewController alloc]init];
thirdViewController.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:3];
UINavigationController *thirdNavController = [[UINavigationController alloc]initWithRootViewController:thirdViewController];
UIViewController *fourthViewController = [[UIViewController alloc]init];
thirdViewController.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:3];
UINavigationController *fourthNavController = [[UINavigationController alloc]initWithRootViewController:fourthViewController];
tabBar.viewControllers = [[NSArray alloc] initWithObjects:homeNavController, reqNavController, thirdNavController, fourthNavController, nil];
tabBar.delegate=self;
tabBar.selectedIndex=0;
UIImageView *homeImg=[[UIImageView alloc]initWithFrame:CGRectMake(0, 432, 80, 49)];
homeImg.tag=11;
homeImg.image=[UIImage imageNamed:@"footer"];
UIImageView *reqImg=[[UIImageView alloc]initWithFrame:CGRectMake(81, 432,80, 49)];
reqImg.tag=12;
reqImg.image=[UIImage imageNamed:@"footer"];
UIImageView *sendImg=[[UIImageView alloc]initWithFrame:CGRectMake(162, 432,80, 49)];
sendImg.tag=13;
sendImg.image=[UIImage imageNamed:@"footer"];
UIImageView *localImg=[[UIImageView alloc]initWithFrame:CGRectMake(243, 432, 80, 49)];
localImg.tag=14;
localImg.image=[UIImage imageNamed:@"footer"];
[tabBar.view addSubview:homeImg];
[tabBar.view addSubview:reqImg];
[tabBar.view addSubview:sendImg];
[tabBar.view addSubview:localImg];
[[[UIApplication sharedApplication]keyWindow]addSubview:tabBar.view];
目前,我已将上述代码放在扩展 UITabBarController 的 ViewController TabViewController 的 viewDidLoad 中。在我的 webView 控制器中,我输入了以下代码 -
TabViewController *tab=[[TabViewController alloc] init];
tab.userInfo=userInfo;
[self presentViewController:tab animated:YES completion:nil];
但是,只要我单击已打开的选项卡以外的任何选项卡,该应用程序就会崩溃。请帮忙。