我遇到了一个非常奇怪的问题。
这是我的应用程序委托中的代码结构:
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”中的新标题,并且导航栏的后退按钮也出现了。但是,视图没有改变,我仍然可以访问 collectionview。
但是,如果我按下 tabbarcontroller 上的其他选项卡,例如 accountviewcontroller,然后再次按回 homeviewcontroller 的旧选项卡,现在将显示视图。这是一个非常奇怪的行为,我不知道它为什么会发生。
我还检查了在每个视图控制器中,self.navigationcontroller 不是 nil