如何在切换到另一个tabbaritem时从uitabbarcontroller隐藏先前的uiview

时间:2014-11-17 06:18:12

标签: ios uitabbar uitabbaritem

我有两个tabbars上下,当我点击tabbaritem UIView show时,但是当我点击另一个tabbar项时,前一个视图仍然保留在控制器中。代码是

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{


    switch (item.tag) {
        case 0:
        {
            NSLog(@"home");
            homeViewController *homeVc= [[homeViewController alloc] initWithNibName:@"homeViewController" bundle:nil];
            [self.view insertSubview:homeVc.view belowSubview:tabBar];
            break;
        }
        case 1:
        {

             NSLog(@"compus");
    compusViewController *compusVc= [[compusViewController alloc] initWithNibName:@"compusViewController" bundle:nil];
        [self.view insertSubview:compusVc.view belowSubview:tabBar];
            break;

        } 

1 个答案:

答案 0 :(得分:0)

没有直接的方法可以简单地删除所有子视图。您必须为所有子视图调用removeFromSuperview。幸运的是,代码简洁明了。使用[self.containerView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]。 - Sikhapol Saijit