2012-09-17 158 views
0

我是新來的ios,我有一個tabbar控制器的問題。我在我的項目中使用了兩個標籤欄控制器。一個在應用程序午餐時加載,它運行良好。我想在didselect行加載另一個。如何執行此操作。我做了很多實驗,但沒有任何作用。如何使用導航控制器加載tabbar控制器xib

+0

[你嘗試過什麼(http://mattgemmell.com/2008/12/08/what-have-you-tried/) – akk

+0

你的問題的標題和你的問題的說明似乎在訴說不同的東西。你究竟想要做什麼?你的父視圖控制器是什麼? NavigationController或Tabbarcontroller? – Neo

回答

0
-(void) hidetabbar { 
    [UIView animateWithDuration:0.5 
         animations:^{ 
          for(UIView *view in tabBarController.view.subviews) 
          { 
           if([view isKindOfClass:[UITabBar class]]) 
           { 
            if (hiddenTabBar) { 
             [view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)]; 
            } else { 
             [view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)]; 
            } 
           } else { 
            if (hiddenTabBar) { 
             [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)]; 
            } else { 
             [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)]; 
            } 
           } 
          } 
         }]; 
    hiddenTabBar = !hiddenTabBar; 
} 


when u r clicking on the table view did select row hide the tabbar in the viewcontroller that u r sending 

-(void)viewDidAppear:(BOOL)animated{ 
    [super viewDidAppear:YES]; 
    [((AppDelegate*)[[UIApplication sharedApplication]delegate]) hidetabbar]; 
} 








-(void)tabBarControllerView 
{ 
    tabBarController = [[UITabBarController alloc] init]; 
    tabBarController.view.backgroundColor = [UIColor blackColor]; 
    tabBarController.delegate = self; 
    //Add some tabs to the controller... 

    //----First tab----// 
    //-----second Tab -----// 

    //------3rd tab--// 

    //-----4th tab bar--------// 

    //-----5th tab bar--------// 

    [self.view addSubview:tabBarController.view]; 



    [navigationController pushViewController:tabBarController animated:YES]; 
    tabBarController.tabBar.tag=100; 

    tabBarController.view.hidden = NO; 
} 


- (void)tabBarController:(UITabBarController *)tabBarControllers didSelectViewController:(UIViewController *)viewController 
{ 
    if (tabBarControllers.selectedIndex == 0) 
    { 
    } 
    else if (tabBarControllers.selectedIndex == 1) 
    { 

    } 
    else if (tabBarControllers.selectedIndex == 2) 
    { 


    } 
    else if (tabBarControllers.selectedIndex == 3) 
    { 
    } 
    else if (tabBarControllers.selectedIndex == 4) 
    { 

    } 
} 

隱藏其中烏爾做沒有選擇表,並添加另一個標籤欄在視圖控制器主選項卡欄.. 嘗試一些像這樣的東西,它可以幫助ü

+0

嗨,我的父視圖控制器是tabbar控制器。在didselect行我想加載一個新的tabbar控制器。如何去做 – user1376474

+0

爲你的父視圖標籤欄控制器賦予一個標籤值,並在選擇行中將u導向另一個視圖控制器,檢查tabcontroller視圖對象,並在標籤值的幫助下從該視圖控件中移除標籤欄查看cotroller並在該類中添加你的新標籤欄控制器 – 08442

0

添加以下代碼在didSelect事件

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

    NSArray*tabBarimageArray=[NSArray arrayWithObjects:@"firstTabImage.png",@"secondTabImage.png", nil]; 




    YourFirstTabRootViewController *firstVc = [[YourFirstTabRootViewController alloc]initWithNibName:@"YourFirstTabRootViewController" bundle:nil]; 




    UINavigationController *firstNavigationController=[[UINavigationController alloc]initWithRootViewController:firstVc]; 


    YourSecondTabRootViewController *secondVc = [[YourSecondTabRootViewController alloc]initWithNibName:@"YourFirstTabRootViewController" bundle:nil]; 




    UINavigationController *secondNavigationController=[[UINavigationController alloc]initWithRootViewController:secondVc]; 


    NSArray *VCs = [[NSArray alloc] initWithObjects:firstNavigationController,secondNavigationController nil]; 
    NSArray *names = [NSArray arrayWithObjects: 
         NSLocalizedString(@"Tab1", @""), 
         NSLocalizedString(@"Tab2", @""), 

         nil]; 

    NSMutableArray *tabBarViewControllers = [[NSMutableArray alloc] initWithCapacity:[VCs count]]; 
    NSInteger index = 0; 


    for (id controller in VCs) { 




     UINavigationController * navController = controller ; 
       // THIS SETS UP THE TAB BAR ITEMS/IMAGES AND SET THE TAG FOR TABBAR_ITEM_TAGS 
       NSString *tabName = [names objectAtIndex:index]; 
       UIImage *tabImage = [UIImage imageNamed:[NSString stringWithFormat:[tabBarimageArray objectAtIndex:index]]]; 
       navController.title = tabName; 
       UITabBarItem *tempTab = [[UITabBarItem alloc] initWithTitle:tabName 
                     image:tabImage 
                     tag:index]; 
       navController.tabBarItem = tempTab; 

       [tabBarViewControllers addObject:navController]; 
     index ++; 

     } 





    [ tabBarController setViewControllers:tabBarViewControllers]; 

    [self presentModalViewController:tabBarController animated:YES]; 
+0

如何隱藏父標籤欄... – user1376474