iOS-Objective-C:推送View Controller时,Tabbar不显示(隐藏)

时间:2017-06-13 13:18:08

标签: ios objective-c navigationbar tabbar

我的故事板如下: enter image description here

我的appdelegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UITabBarController *tabBarController = [storyboard instantiateViewControllerWithIdentifier:@"rootTabBarVC"];
    self.window.rootViewController = tabBarController;
    return YES;
}

我有侧面菜单,我按照以下方式推送VC1:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
VC1 *contr = [storyboard instantiateViewControllerWithIdentifier:@"VC1"];
[self.navCon pushViewController:contr animated:YES];

我的问题是:VC1正在推动但是tabbar被隐藏了。那么,任何人都可以帮我在推VC上显示tabbar吗?

2 个答案:

答案 0 :(得分:0)

您的视图控制器hidesBottomBarWhenPushed可能设置为true。您也可以在故事板中检查,如屏幕截图所示。enter image description here

答案 1 :(得分:0)

在您的 AppDelegate.h 文件集中尝试以下操作:

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UITabBarController *tabBarCon;

然后在 AppDelegate.m 文件中:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *viewController =  [storyboard instantiateViewControllerWithIdentifier:@"InitialNavCon"];
    self.window.rootViewController = viewController; 
}

最后,当您从侧边菜单导航时,可以在界面中将此放置到标签栏控制器的委托 UITabBarControllerDelegate ,然后将appdelegate声明为:

@property (strong, nonatomic) AppDelegate *appDelegate; 
// for NAVIGATION use this :
  self.appDelegate.tabBarCon = [self.storyboard instantiateViewControllerWithIdentifier:@"MainTabBarController"]; // Set your TABBAR CONTROLLER TO "MainTabBarController"
  [[UITabBar appearance] setItemWidth:self.appDelegate.window.frame.size.width/4.0];
  self.appDelegate.tabBarCon.delegate=self;
  [self.navigationController pushViewController:self.appDelegate.tabBarCon animated:YES]; // then navigate

使用以下基本要素设置您的初始导航控制器: enter image description here

您与标签栏的连接应像这样,并且每个tabVC都有一个导航控制器:enter image description here

相关问题