nrlnishan / ViewPager-Swift

Simple View Pager library for swift using UIPageViewController and Scroll View
MIT License
174 stars 48 forks source link

Navigating between to different view controllers with identifiers #34

Closed Gouthamansriniv closed 6 years ago

Gouthamansriniv commented 6 years ago

Hello can you please help to switch between three different view controllers

func viewControllerAtPosition(position:Int) -> UIViewController { let vc = self.storyboard?.instantiateViewController(withIdentifier: "ItemViewController") as! ItemViewController

    let vc2 = self.storyboard?.instantiateViewController(withIdentifier: "second") as! SecondViewController
    let vc3 = self.storyboard?.instantiateViewController(withIdentifier: "third") as! ThirdViewController
    vc.itemText = "\(tabs[position].title!)"
    return vc,vc2,vc3
}
nrlnishan commented 6 years ago

You have to provide 1 view controller for each position. For eg For position 0 = FirstViewController For position 1 = SecondViewController `

if position == 0 {

    let vc1 = self.storyboard?.instantiateViewController(withIdentifier: "ItemViewController") as! ItemViewController
    return vc1

} else if position == 1 {

    let vc2 = self.storyboard?.instantiateViewController(withIdentifier: "second") as! SecondViewController
    return vc2

} else {

    let vc3 = ....
    return vc3

} `

Gouthamansriniv commented 6 years ago

Thanks for your support nrlnishan.