隐藏自定义UITabBar

问题描述:

我已经成功创建并实现了自定义UITabBarController,自定义UITabBar后面this tutorial。它工作正常,直到我必须隐藏它。隐藏自定义UITabBar

我没有使用故事板或IB,我必须获得对我现有的UITabBarController的引用,屏幕上将隐藏自定义的UIView。我试图做这种方式,但它只是创造UITabBarController的新实例,而不是指向我原来的例子中,我在屏幕上看到:

SGTabBarController *tabBarController = [[SGTabBarController alloc] init]; 
[tabBarController hideCustomTabBar]; 

SGTabBarController.h

@interface SGTabBarController : UITabBarController 

@property (nonatomic) int tabBarHeight; 

-(void)hideCustomTabBar; 
-(void)showCustomTabBar; 

@end 

SGTabBarController.m

-(void)hideCustomTabBar{ 
    customTabBarView.hidden = YES; 
    NSLog(@"HIDDEN!!!"); 
} 

-(void)showCustomTabBar{ 
    customTabBarView.hidden = NO; 
} 

任何关于如何GE的想法对它?提前致谢!

+0

您是否将tabBarController设置为AppDelegate中的rootViewController?我以编程方式做到这一点,并能够随时访问tabBarController。 – TheJer 2013-03-07 17:40:08

+0

@TheJer让它成为答案,我会接受它!真棒! – 2013-03-07 18:05:59

我如何能够访问应用程序中任何位置的自定义UITabBarController。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
// Set up the Dashboard 
// 
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
[_window makeKeyAndVisible]; 

UITabBarController *tabBarController = [[UITabBarController alloc] init]; 
NSMutableArray *tabBarItems = [@[] mutableCopy]; 

// Repeat this for any amount of ViewControllers 
UITableViewController *tableViewController = [UITableViewController alloc] initWithStyle:UITableViewStylePlain]; 
UINavigationController *navController = [UINavigationController alloc] initWithRootViewController:tableViewController]; 

[tabBarItems addObject:navController]; 
tabBarController.viewControllers = tabBarItems; 
self.window.rootViewController = tabBarController; 

return YES; 
} 
+0

太棒了!正是我需要的! – 2013-03-07 21:44:39