簡體   English   中英

如何使用導航控制器加載Tabbar Controller Xib

[英]How to load a tabbar controller xib using navigation controller

我是ios的新手,標簽欄控制器有問題。 我在項目中使用了兩個標簽欄控制器。一個在應用午餐時加載,並且運行良好。我想在didselect行中加載另一個。 我做了很多實驗,但沒有任何效果。

-(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)
    {

    }
}

在該視圖控制器中隱藏主選項卡欄,您在其中做完選擇表並添加另一個選項卡欄。嘗試這樣的事情可能會幫助您

在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];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM