[英]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.