iphone - IOS从tabbarcontroller中的navigationcontroller推送viewcontroller但不显示

标签 iphone ios navigationcontroller tabbarcontroller

我遇到了一个非常奇怪的问题。

这是我的应用程序委托(delegate)中的代码结构:

self.accountViewController = [[AccountViewController alloc] initWithNibName:@"AccountViewController" bundle:nil];
self.homeViewController = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
self.exploreViewController = [[ExploreViewController alloc] initWithNibName:@"ExploreViewController" bundle:nil];
self.activityViewController = [[ActivityViewController alloc] initWithNibName:@"ActivityViewController" bundle:nil];
self.homeNavigationController = [[UINavigationController alloc] initWithRootViewController:self.homeViewController];
self.accountNavigationController = [[UINavigationController alloc] initWithRootViewController:self.accountViewController];
self.activityNavigationController = [[UINavigationController alloc] initWithRootViewController:self.activityViewController];
self.exploreNavigationController = [[UINavigationController alloc] initWithRootViewController:self.exploreViewController];

self.tabBarController = [[MyOwnTabBarController alloc] init];
[self.tabBarController setDelegate:self];
[self.tabBarController setViewControllers:[NSArray arrayWithObjects:self.homeNavigationController, self.exploreNavigationController,self.activityNavigationController,self.accountNavigationController,nil]];
[self.tabBarController setSelectedIndex:0];
[self.navController setViewControllers:[NSArray arrayWithObjects:self.welcomeViewController, self.tabBarController, nil] animated:NO];

对于 self.navController,我这样定义

self.navController = [[UINavigationController alloc] initWithRootViewController:self.welcomeViewController];
self.window.rootViewController = self.navController;

因此,在显示 tabbarcontroller 后,我将位于 homeviewcontroller,其中有一个 collectionview。它成功显示多个单元格。当我点击单元格时,

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    [self.navigationController pushViewController:vc animated:YES];
}

我看到导航栏已更改为“vc”中的新标题,并且导航栏的后退按钮也显示了。但是, View 没有改变,我仍然能够访问 Collection View 。

但是,如果我按 tabbarcontroller 上的其他选项卡(例如 accountviewcontroller),然后再次按回到 homeviewcontroller 的旧选项卡,现在将显示 View 。这是一种非常奇怪的行为,我不知道为什么会发生。

我还检查了每个 View Controller 中, self.navigationcontroller 不为零

最佳答案

发现问题出在tabbarcontroller的子类上

- (void)viewWillAppear:(BOOL)animated

缺失

[super viewWillAppear:animated];

关于iphone - IOS从tabbarcontroller中的navigationcontroller推送viewcontroller但不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15516224/

相关文章:

iphone - 我还能如何避免泄漏这个 Core Foundation 对象?

iphone - 如何计算贷款还款额

c# - 如何在没有 IDE 的情况下使用 Xamarin?

ios - isEqualToString : gives out of bound exception

xcode - Swift 2 - 如何将导航 Controller 后退按钮自定义为自定义按钮?

css - 上升和下降按钮是如何制作的?

iphone - 如何更改 OpenGL 中的旋转中心

ios - 如果 iphone 扬声器有故障/有缺陷,AVAudioSession 实例会发生什么?

ios - 关于内存警告的问题

ios - 如何找出属于当前 viewController 的导航 Controller ?