Tôi muốn thêm một Thanh Điều khiển Thanh vào Luồng ứng dụng hiện tại của mình. Hiện tại tôi có một trang có nút bấm khi mở một khung nhìn mới với chế độ xem web, nơi người dùng đăng nhập và sau khi đăng nhập, tôi muốn đưa anh ta đến trang chủ của anh ấy, nơi thanh điều hướng có tên của anh ấy và nút đăng xuất ở bên phải . Trang chủ cũng phải có một thanh tab với 3 tab khác nhau. Tôi có thể tải chế độ xem trang chủ từ chế độ xem web và nhận thanh điều hướng. Nhưng tôi không thể thêm tabBar và làm cho nó hoạt động. Tôi nhầm lẫn về nơi để thêm mã để thêm TabBar. Tôi đang sử dụng mã dưới đây để thêm thanh tab -Thêm Bộ điều khiển Thanh tab Lập trình cho Dòng Ứng dụng hiện tại
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];
Hiện nay tôi đã đặt mã trên trong viewDidLoad của một TabViewController ViewController kéo dài UITabBarController. Trong bộ điều khiển webView của tôi, tôi đã đặt mã sau đây -
TabViewController *tab=[[TabViewController alloc] init];
tab.userInfo=userInfo;
[self presentViewController:tab animated:YES completion:nil];
Nhưng ứng dụng gặp sự cố ngay khi tôi nhấp vào bất kỳ tab nào khác ngoài tab đang mở. Vui lòng trợ giúp.
bạn phải kiểm tra cây tầm nhìn của bạn ... Trong đó xem bạn đang thêm thanh tab .. – Shivaay
Tôi muốn thêm tabBar trong chế độ xem xuất hiện sau khi đăng nhập - tức là chế độ xem sau chế độ xem web trong cây chế độ xem. –
Bạn đã thử tạo một 'UINavigationController' như một trình điều khiển xem gốc và đẩy TabViewController của bạn khi đăng nhập? – Devang