我如何使用 XLPagertabStrip 以编程方式切换到子 ViewController。我有一个名为 Parentcontroller 的 ParentViewController,包括三个名为 Child1VC、Child2VC、Child3VC 的 ChildViewController。每个具有 tableViews 的 childviewController,我想在选择 TableView 中的项目时从 Child1 移动到 Child 2。我已经编码以从子 Controller 切换,但它打破了它的 NavigationViewControllers
在这里,我在 Child1VC 的“didSelectRowAt”方法中添加了如下代码:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let center = storyboard?.instantiateViewController(withIdentifier: "ParentViewController") as? ParentViewController
self.present(center!, animated: true, completion: nil)
}
在 ParentViewController 的 viewDidAppear 中添加如下代码
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)
self.moveToViewControllerAtIndex(1)
}
它正在移动到下一个子选项卡,但它破坏了 NavigationViewController。
最佳答案
发生的事情是您从父 View Controller 而不是导航 Controller 呈现 subview Controller 。我想你想做的是
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let vc = storyboard?.instantiateViewController(withIdentifier: "ParentViewController") as! ParentViewController
self.navigationController!.pushViewController(vc, animated: true)
}
同样这样做它不会成为父/ subview Controller 。
关于ios - ChildViewController 打破 XLPagerTabStrip 中的 NavigationViewController - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48052202/