UITabBarItem显示/隐藏

时间:2012-03-16 10:44:35

标签: objective-c uitabbar uitabbaritem

早上好,我正试图隐藏一个UITabBarItem,在这里看了很多帖子后,我疯了......我可以正确地获得tabItem,但它并没有隐藏。我在Storyboard中设置了TabBar。

这是我的代码..我尝试过的3个选项中没有一个...

任何帮助将不胜感激

@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;
}

1 个答案:

答案 0 :(得分:0)

如果您正在使用xcode 4.x尝试通过选择要嵌入tabBarController的UIview并转到编辑器>嵌入>来尝试这样做。标签栏控制器。我这样做,效果更好。