iosswiftxlpagertabstrip

ChildViewController breaks NavigationViewController in XLPagerTabStrip - Swift


How can i programatically swich to child ViewControllers using XLPagertabStrip. I have a ParentViewController named Parentcontroller including three ChildViewController named Child1VC,Child2VC,Child3VC. each childviewController having tableViews,I want to move from Child1 to Child 2 when an item in table view selected.I have coded to switch from child controllers but it breaks its NavigationViewControllers

Here, I have added the code in "didSelectRowAt" method of Child1VC follows:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
   let center = storyboard?.instantiateViewController(withIdentifier: "ParentViewController") as? ParentViewController
   self.present(center!, animated: true, completion: nil)
}

Added following code to viewDidAppear in ParentViewController

 override func viewDidAppear(_ animated: Bool) {
   super.viewDidAppear(true)

   self.moveToViewControllerAtIndex(1)
 }

It is moving to next child tab, but it breaks NavigationViewController.


Solution

  • What is happening is your presenting the child view controllers from the parent and not the navigation controller. I think what you want to do is

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
       let vc = storyboard?.instantiateViewController(withIdentifier: "ParentViewController") as! ParentViewController
       self.navigationController!.pushViewController(vc, animated: true)
    }
    

    Also doing it this way it won't be parent/child view controllers.