问题描述
我有一个tabbar - > navigationcontroller结构。在其中一个选项卡中,我想在两个UIViewControllers之间切换(和UITableViewController准确无误),使用位于导航栏中的UISegmentedControl。
I have a tabbar -> navigationcontroller structure. In one of these tabs, I want to switch between two UIViewControllers (a KalViewController and a UITableViewController to be be exact), using a UISegmentedControl located in the Navigation Bar.
目前,我有第三个UIViewController,它会在段值更改时弹出并推送相应的ViewControllers。我不认为这是正确的方法,它也会破坏导航堆栈(当我点击条形项目时,导航控制器进入根控制器,这将无法工作)。而且还有另一个与Kal组件相关的错误。
Currently, I have a third UIViewController, that pops and pushes the appropriate ViewControllers on segment value change. I don't think thats the right way to do it and it also destroys the navigation stack (when I tap on the bar item, the navigation controller goes the root controller, which won't work). And there's even another bug, related to the Kal Component.
那么,正确的方式是什么?
推荐答案
正确的方法是让控制器处理 UISegmentedControl
将控制器的视图添加为子视图。
The right way to do it is to have the controller handling the UISegmentedControl
add the views of the controllers as subviews.
[self.view addSubview:controller.view];
您有责任发送 viewWillAppear:
和等等。
编辑:您所谈论的偏移量可以使用以下方式进行调整:
The offset you're talking about can be adjusted using:
controller.view.frame = CGRectMake(x, y, width, height);
编辑2:响应tc。的评论:
来自 UISplitViewController的文档
:
这不是神奇的,也没有理由不能自己编写类似的控制器。事实上我已经完成了它并且工作正常。
This is not magical and there is no reason why you wouldn't be able to write a similar controller yourself. In fact I've done it and it worked just fine.
这篇关于使用UISegmentedControl在UIViewControllers之间切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!