0

我已经按照本教程UITabBarController成功创建并实现了一个自定义。它工作正常,直到我不得不隐藏它。UITabBar

我没有使用 Storyboards 或 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;
}

关于如何实现它的任何想法?提前致谢!

4

1 回答 1

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;
}
于 2013-03-07T18:22:59.703 回答