iOS 9.0 Tabbar自动隐藏,viewcontroller在推送时消失

时间:2016-09-26 08:04:24

标签: ios objective-c uitabbarcontroller ios9 pushviewcontroller

我有一个TabBarController,带有4个Tab。当我从选项卡中推送ViewController时,选项卡会自动隐藏,并且在View中不显示任何内容。但ViewController包含一个包含数据的tableview。我也实现了tableview委托。我没有得到tableview委托日志。

在appdelegate中的

didFinishLaunchingWithOptions()

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

self.homeScreen = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.rootNav = [[UINavigationController alloc]initWithRootViewController:self.homeScreen];

self.window.rootViewController = self.rootNav;

[self.window makeKeyAndVisible];

在此处加载TabBar:

 myAppDelegate.myTabBarController.selectedIndex = 0;
myAppDelegate.myTabBarController.tabBar.translucent = NO;
myAppDelegate.myTabBarController.tabBar.opaque = YES;


location_select *tab1 = [[location_select alloc] initWithNibName:@"location_select" bundle:nil];
tab1.tabBarItem.image = [UIImage imageNamed:@"Restaurants.png"];
location_select *tab2 = [[location_select alloc] initWithNibName:@"location_select" bundle:nil];
tab2.title = @"Cart";
tab2.tabBarItem.image = [UIImage imageNamed:@"Cart.png"];
Deal_ViewController *tab3 = [[Deal_ViewController alloc] initWithNibName:@"Deal_ViewController" bundle:nil];
tab3.title = @"Deals";
tab3.tabBarItem.image = [UIImage imageNamed:@"Deals.png"];

MoreViewController *tab4 = [[MoreViewController alloc] initWithNibName:@"MoreViewController" bundle:nil];
tab4.title = @"More";
tab4.tabBarItem.image = [UIImage imageNamed:@"More.png"];
myAppDelegate.myTabBarController.viewControllers = [NSArray arrayWithObjects:tab1,tab2,tab3,tab4,nil];
[myAppDelegate.rootNav pushViewController:myAppDelegate.myTabBarController animated:YES];

从Tab 4,我推送Profile_ViewController:

 Profile_ViewController *vc = [[Profile_ViewController alloc] initWithNibName:@"Profile_ViewController" bundle:[NSBundle mainBundle]];
 [self.navigationController pushViewController:vc animated:YES];

我已经在那里申请了:

myAppDelegate.myTabBarController.hidesBottomBarWhenPushed=NO; 
and 
[self.tabBarController setHidesBottomBarWhenPushed:NO];

在Profile_ViewController的viewWillAppear中。没有任何作品。我只是看到一个空白的白色屏幕。

2 个答案:

答案 0 :(得分:0)

您可能将您的架构保持如下 导航控制器--->标签栏控制器 - > 4个子视图控制器

你需要这样做 标签栏控制器 - > 4个子控制器(这4个子视图控制器中的每一个都有自己的导航控制器)。

答案 1 :(得分:0)

location_select *tab1 = [[location_select alloc] initWithNibName:@"location_select" bundle:nil];
tab1.tabBarItem.image = [UIImage imageNamed:@"Restaurants.png"];
location_select *tab2 = [[location_select alloc] initWithNibName:@"location_select" bundle:nil];
tab2.title = @"Cart";
tab2.tabBarItem.image = [UIImage imageNamed:@"Cart.png"];
Deal_ViewController *tab3 = [[Deal_ViewController alloc] initWithNibName:@"Deal_ViewController" bundle:nil];
tab3.title = @"Deals";
tab3.tabBarItem.image = [UIImage imageNamed:@"Deals.png"];

MoreViewController *tab4 = [[MoreViewController alloc] initWithNibName:@"MoreViewController" bundle:nil];
tab4.title = @"More";
tab4.tabBarItem.image = [UIImage imageNamed:@"More.png"];




UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:tab1];

UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:tab2];

UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:tab3];

UINavigationController *nav4 = [[UINavigationController alloc] initWithRootViewController:tab4];

myAppDelegate.myTabBarController.viewControllers = [NSArray arrayWithObjects:nav1,nav2,nav3,nav4,nil];
[myAppDelegate.rootNav pushViewController:myAppDelegate.myTabBarController animated:YES];

and then later on to push your vc to tab 4 you should do

Profile_ViewController *vc = [[Profile_ViewController alloc] initWithNibName:@"Profile_ViewController" bundle:[NSBundle mainBundle]];
[nav4 pushViewController:vc animated:YES];

这是与您的查询相关的解决方案,可能对您有所帮助