0

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

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

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

4

3 回答 3

1

发现问题出在 tabbarcontroller 的子类中

- (void)viewWillAppear:(BOOL)animated

不见了

[super viewWillAppear:animated];
于 2013-03-20T22:10:56.080 回答
0
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];
if (tabBarControllerObj!=nil) {
tabBarControllerObj=nil;
}
tabBarControllerObj=[[UITabBarController alloc]init];
NSArray *arrayObj=[[NSArray alloc]initWithObjects:self.homeNavigationController,self.accountNavigationController,self.activityNavigationController,self.exploreNavigationController, nil];
[tabBarControllerObj setSelectedIndex:0];
tabBarControllerObj.tabBar.hidden = YES;
[tabBarControllerObj setViewControllers:arrayObj];
[self.window addSubview:tabBarControllerObj.view];
于 2013-03-20T06:47:03.803 回答
0

我认为。只需检查您是否已将导航控制器添加到 tabBar。在下面检查它。如果不是,请告诉我整个场景。

tabBarControllerObj=[[UITabBarController alloc]init];
    NSArray *arrayObj=[[NSArray alloc]initWithObjects:navForView1,navForView2,navForView3,navForView4,navForView5, nil];

    [tabBarControllerObj setSelectedIndex:0];
    tabBarControllerObj.tabBar.hidden = YES;
    [tabBarControllerObj setViewControllers:arrayObj];
    [self.window addSubview:tabBarControllerObj.view];
于 2013-03-20T05:51:33.770 回答