0

am using https://github.com/xmartlabs/XLPagerTabStrip#how-to-change-the-visible-child-view-controller-programmatically in my application ...

on button click from one child i want to move to another child .. i tried:

@IBAction func morenewsbtn(_ sender: Any) {
    print("clicked")
    let mainpage = HomeViewController()
    mainpage.moveToViewController(at: 1, animated: true)
}

but this will not move to another child .. tried this in viewdidappear and its working fine .. but how to use it in button click?

Lama
  • 225
  • 3
  • 15

1 Answers1

0

Because this

let mainpage = HomeViewController() // problem is here
mainpage.moveToViewController(at: 1, animated: true)

is a new VC , you need to make it from the presented one , you can either set a reference to home , or simply use this

let home = self.parent as! HomeViewController
parent.moveToViewController(at: 1)
Sh_Khan
  • 86,695
  • 6
  • 38
  • 57
  • i want to make it from child .. this button is a child 0 and i want to go to 1 when button clicked in it .. HomeViewController is the parent view – Lama Jul 24 '18 at 09:41