我有一个视图控制器(在导航控制器内),它有一个带有2个选项的分段控件和一个容器视图,其中2个UITableViewControllers将根据所选的段显示。
第一个视图通过(crt + click)嵌入并链接到容器加载到故事板中,并且表加载好,表开始在导航栏上方,但是当我更改段而另一个视图加载时从导航栏后面的视图顶部开始。 (当我回到第一个视图时)
要更改视图,请按以下步骤操作: Swift - How to link two view controllers into one container view and switch between them using segmented control?
这是我的代码:
let viewControllerIdentifiers = ["categoriasTVC", "unidadesTVC"]
@IBAction func opcion(sender: AnyObject) {
let newController = (storyboard?.instantiateViewControllerWithIdentifier(viewControllerIdentifiers[sender.selectedSegmentIndex]))! as UIViewController
let oldController = childViewControllers.last! as UIViewController
oldController.willMoveToParentViewController(nil)
addChildViewController(newController)
newController.view.frame = oldController.view.frame
transitionFromViewController(oldController, toViewController: newController, duration: 0, options: .TransitionNone, animations:{ () -> Void in
// nothing needed here
}, completion: { (finished) -> Void in
oldController.removeFromParentViewController()
newController.didMoveToParentViewController(self)
})
}
如何保持导航控制器的插入?