0

我是 ios 新手,标签栏控制器有问题。我在我的项目中使用了两个标签栏控制器。一个在应用程序午餐时加载,它运行良好。我想在 didselect 行加载另一个。如何做到这一点。我做了很多实验,但没有任何效果。

4

2 回答 2

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

    }
}

在该视图控制器中隐藏主标签栏,您在其中执行选择表并添加另一个标签栏..尝试这样的事情它可能对您有所帮助

于 2012-09-17T11:30:54.033 回答
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];
于 2012-09-17T11:33:22.600 回答