2012-03-16 164 views
0

早上好,我试图隐藏一个UITabBarItem,在阅读了很多帖子后,我越来越疯狂....我可以正确地获取tabItem,但它不会隐藏。我在故事板中设置我的TabBar。UITabBarItem显示/隐藏

这里是我的3个选项我试过作品code..none ...

任何帮助会,如果你正在使用的Xcode 4.x的理解

@implementation unidaAppDelegate 

@synthesize window = _window; 
@synthesize tabBarController = _tabBarController; 


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 
    self.tabBarController = [storyboard instantiateViewControllerWithIdentifier:@"myTab"]; 

    NSMutableArray *tabs = [NSMutableArray arrayWithArray:self.tabBarController.viewControllers]; 
    NSLog(@"Array:%@",tabs); 


    /* 
    OPTION 1 

    NSMutableArray *viewControllersCopy = [[self.tabBarController viewControllers] mutableCopy]; 
    [viewControllersCopy removeObjectAtIndex:2]; 
    NSArray *modifiedViewControllers = [[NSArray alloc] initWithArray:viewControllersCopy]; 
    [self.tabBarController setViewControllers:modifiedViewControllers animated:NO]; 

    OPTION 2 

    NSMutableArray *modifyMe = [[self.tabBarController.tabBar items] mutableCopy]; 
    [modifyMe removeObjectAtIndex:2]; 
    NSArray *newItems = [[NSArray alloc] initWithArray:modifyMe]; 
    [self.tabBarController.tabBar setItems:newItems animated:true]; 


    OPTION 3 

    NSLog(@"TabBarItem: %@",[[self.tabBarController.tabBar.items objectAtIndex:2] title]); 
    [[self.tabBarController.tabBar.items objectAtIndex:2] setEnabled:FALSE]; 
    */ 

    sleep(1); 
    return YES; 
} 

回答

0

尝试去做选择你想要嵌入到tabBarController中的UIviews,然后转到编辑器>嵌入>选项卡栏控制器。我这样做,它效果更好。

+0

感谢ClOck,这是我做到的方式,但UITabBarItem抵制隐藏.... – Christian 2012-03-19 07:13:10