简体   繁体   English

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

[英]switch controllers within one tab bar item

What I want to do is to have my table view controller appear when the user presses a tab bar item, and when the user presses a cell in the table I want to switch to a nav controller while retaining the tab bar controller.我想要做的是让我的表格视图 controller 在用户按下选项卡栏项目时出现,并且当用户按下表格中的单元格时,我想切换到导航 controller 同时保留选项卡栏 Z594C38AB03F2C6E0E04C

So far I've been testing my table view in my tab bar controller with a test UIViewController class and trying to switch to that.到目前为止,我一直在我的标签栏 controller 中测试我的表格视图,并尝试切换到它。

I've added the following to my table view delegate method:我已将以下内容添加到我的表视图委托方法中:

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

It just overlaps the nib onto what I already have.它只是将笔尖重叠到我已经拥有的东西上。 I suspect I must clear my existing table view?我怀疑我必须清除现有的表格视图? Also, can I use this method with a UINavigationController?另外,我可以将此方法与 UINavigationController 一起使用吗?

I would like to add that initially I had a navigation controller with the table controllers within.我想补充一点,最初我有一个导航 controller,里面有表格控制器。 However, the first table controller I did not want the top navigation bar.但是,第一个表 controller 我不想顶部导航栏。 I only wanted a top bar until the person drilled down to the second level.我只想要一个顶栏,直到这个人钻到第二层。

Put your table VC back in your navigation stack as the root controller, but add these lines to have the navigation bar hide:将表 VC 作为根 controller 放回导航堆栈中,但添加这些行以隐藏导航栏:

-(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... */
}

You may need to put one or the other of these in the viewDidAppear: / viewDidDisappear: methods if the animation looks awkward or happens at the wrong time.如果 animation 看起来很尴尬或发生在错误的时间,您可能需要将其中一个或另一个放在viewDidAppear: / viewDidDisappear:方法中。

Also, as far as showing/hiding the tab bar goes, check out the hidesBottomBarWhenPushed field on UIViewController .此外,就显示/隐藏标签栏而言,请查看UIViewController上的hidesBottomBarWhenPushed字段。

QUick Solution: Load your View Controller on the click(tabBar Item).快速解决方案:在点击(tabBar 项目)上加载您的视图 Controller。 Navigate within the view controller for loading another view on selecting cell.在视图 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 关闭标签栏控制器 - Closing tab bar controllers 标签栏控制器和导航控制器的问题 - Problem with Tab Bar Controllers and Navigation Controllers 标签栏控制器中的导航控制器 - Navigation Controllers in tab bar controller 重叠嵌套标签栏控制器 - Overlapped Nested Tab Bar Controllers 在选项卡栏控制器 - >导航控制器 - >视图控制器的层次结构内旋转视图控制器 - Rotating view controllers within a hierarchy of Tab Bar Controller -> Navigation Controller -> View Controller 如何获取选项卡栏控制器中包含的所有视图控制器? iPhone开发人员 - How to get all the view controllers that is included within a tab bar controller? Iphone dev 在视图控制器->标签栏控制器->导航控制器->视图控制器的层次结构内旋转视图控制器 - Rotating view controllers within a hierarchy of View Controller -> Tab Bar Controller -> Navigation Controller -> View Controller iOS7-标签栏内仅某些View Controller的锁定方向? - iOS7 - Lock Orientation of only SOME View Controllers that are within a Tab Bar? 将两个导航控制器添加到一个选项卡栏 - add two navigation controller to one Tab bar Item 导航栏中的标签栏 - Tab bar within Navigation bar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM