在一个标签栏项目中切换控制器

时间:2011-08-16 01:34:09

标签: iphone objective-c ios

我想要做的是当用户按下标签栏项时显示我的表视图控制器,当用户按下表格中的单元格时,我想在保留标签栏控制器的同时切换到导航控制器。

到目前为止,我一直在我的标签栏控制器中使用测试UIViewController类测试我的表视图并尝试切换到该视图。

我已将以下内容添加到我的表视图委托方法中:

test *newTest = [[test alloc] init];
[self.view insertSubview:newTest.view atIndex:0];

它只是将笔尖重叠到我已经拥有的东西上。我怀疑我必须清除现有的桌面视图?另外,我可以将此方法与UINavigationController一起使用吗?

我想补充一点,我最初有一个带有表控制器的导航控制器。但是,第一个表控制器我不想要顶部导航栏。我只想要一个顶杆,直到这个人钻到第二级。

2 个答案:

答案 0 :(得分:1)

将表VC作为根控制器放回导航堆栈中,但添加这些行以隐藏导航栏:

-(void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];
  [self setNavigationBarHidden:YES animated:animated];
  /* ...your existing code... */
}

-(void)viewWillDisappear:(BOOL)animated {
  [super viewWillDisappear:animated];
  [self setNavigationBarHidden:NO animated:animated];
  /* ...your existing code... */
}

如果动画看起来很笨或在错误的时间发生,您可能需要在viewDidAppear: / viewDidDisappear:方法中放入其中一个。

此外,只要显示/隐藏标签栏,请查看UIViewController上的hidesBottomBarWhenPushed字段。

答案 1 :(得分:0)

QUick解决方案:在点击(tabBar项目)上加载View Controller。在视图控制器中导航以在选择单元格上加载另一个视图。

Methods that can be used:


 tabBarController.viewControllers=/*Array of ViewControllers*/
  [tabBarController.theTabBar setHidden:YES]; //Use it if you want to hide from anywhere in your program
 tableView:didSelectRowAtIndexPath://for loading another view on selecting cell