我想向我當前的應用程序流程添加選項卡控制器控制器。目前,我有一個頁面上有一個按鈕,點擊按鈕打開一個新的視圖控制器,其中包含用戶登錄的網頁視圖,登錄後我想將他帶到他的主頁,其中導航欄有他的名字和右側的註銷按鈕。主頁還應該有一個帶有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];
目前我已經把一個視圖控制器TabViewController延伸的UITabBarController的viewDidLoad中上面的代碼。在我的web視圖控制器我已經把下面的代碼 -
TabViewController *tab=[[TabViewController alloc] init];
tab.userInfo=userInfo;
[self presentViewController:tab animated:YES completion:nil];
但是當我點擊一個比已經打開其他任何選項卡中的應用程序,一旦崩潰。 請幫助。
你必須檢查你的視圖樹......在這查看你正在添加標籤欄.. – Shivaay 2013-05-06 10:34:04
我想在視圖中添加tabBar在記錄後in - 即視圖樹中webview之後的視圖。 – 2013-05-06 10:45:58
您是否嘗試創建'UINavigationController'作爲根視圖控制器並在登錄時推送TabViewController? – Devang 2013-05-06 12:20:13