2013-03-07 79 views
0

我已經成功創建並實現了自定義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

回答

1

我如何能夠訪問應用程序中任何位置的自定義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