uias / Pageboy

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

Always move to page index 3 when adding new childController #135

Closed aaasifrz9 closed 6 years ago

aaasifrz9 commented 6 years ago

I am trying to insert a new ChildViewController in 'Example' code as mentioned below:-

@IBAction func insert(_ sender: Any) {

        let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
        let viewController = storyboard.instantiateViewController(withIdentifier: "ChildViewController") as! ChildViewController
        viewController.index = pageControllers.count + 1
        pageControllers.append(viewController)
}

This code inserts child controller in last but It always moves to index 3. I don't know why it always set index 3.

I also tried to scroll to inserted index after appending viewController in pageControllers using

scrollToPage(.at(index: self.pageControllers.count), animated: true)

but no success. Still moves to index 3.

I want to work on some tasks like Insert, Delete, Update. But I am not getting any point to perform these tasks.

Can You please help? 1- How can I insert a new controller and move to the inserted controller? 2- How can I delete any specific index controller and move to the next/last controller? 3- How to refresh any specific index controller without calling reloadPages()?

File PageViewController.swift link: https://www.dropbox.com/s/yvsek6vocmclh06/PageViewController.swift?dl=0

SirWellington commented 6 years ago

I'm trying to do something similar of moving pages around at runtime depending on the context. Is there a way to do this using PageBoy?

msaps commented 6 years ago

@SirWellington @aaasifrz9 it's not possible with the current API, but I plan on adding this feature in the near future.

Follow #155 for updates