uias / Pageboy

📖 A simple, highly informative page view controller
MIT License
1.99k stars 154 forks source link

scrollToPage not working when called from parent viewcontroller #231

Open sumitpaul opened 5 years ago

sumitpaul commented 5 years ago

I have a parent view controller with a container view that has a pageboy viewcontroller embedded in it. I have next/previous buttons in the parent viewcontroller, as I don't want the buttons to slide with the pages embedded in the pageboy viewcontroller. But when I try to call the scrollToPage functions in the parent nothing happens. What am I doing wrong?

My code:`

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "CarouselEmbedSegue" {
        let vc = segue.destination as! ContainedCarouselVC
        guard let selectedLocation = location else { return }
        vc.themeColor = selectedLocation.color
        vc.locationToLoad = selectedLocation
    }
}

@IBAction func slidePrevious(_ sender: Any) {
    let vc =  ContainedCarouselVC()
    vc.scrollToPage(.previous, animated: true)
}

@IBAction func slideNext(_ sender: Any) {
    let vc = ContainedCarouselVC()
    vc.scrollToPage(.next, animated: true)
}

`

sugitatestblue commented 2 years ago

@sumitpaul

You created new instance in slidePrevious and slideNext methods. let vc = ContainedCarouselVC()

if you refer to ContainedCarouselVC's instance. I guess it works.