uias / Pageboy

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

Crash with message "Invalid parameter not satisfying: [views count] == 3" + FIX #140

Closed salvasp closed 6 years ago

salvasp commented 6 years ago

If swipe quickly between pages I sometime get the error inconsistent exception "Invalid parameter not satisfying: [views count] == 3"

seems can be fixed replacing inside "open class PageboyViewController: UIViewController"

pageViewController.setViewControllers(viewControllers,
                                                  direction: direction.pageViewControllerNavDirection,
                                                  animated: false,
                                                  completion:
                { (finished) in
                    self.isUpdatingViewControllers = false

                    if !animated {
                        completion?(finished)
                    }
            })    

with

     DispatchQueue.main.async {
            pageViewController.setViewControllers(viewControllers,
                                                  direction: direction.pageViewControllerNavDirection,
                                                  animated: false,
                                                  completion:
                { (finished) in
                    self.isUpdatingViewControllers = false

                    if !animated {
                        completion?(finished)
                    }
            })            
        }
msaps commented 6 years ago

@salvasp thanks for all the detail, just released a new version with this fix in. Let me know how you get on with it! 😄 v2.3.4

salvasp commented 6 years ago

yes seems to work. Have you panned something like extending func viewController(for pageboyViewController: PageboyViewController, at index: PageboyViewController.PageIndex) -> UIViewController? with somentig like func viewController(for pageboyViewController: PageboyViewController, at index: PageboyViewController.PageIndex, reusingViewController: UIViewController?) -> UIViewController? to reuse the cached view controllers? I commented the issue #124 with some idea but for now I'm using in one case the variable [UIViewController?] (in the comments after the NSCache row) because i have just 6 view controllers. in another case 50+ view controllers I create a view controller (let controller = storyboard.instatiate....; return controller) each time "viewController for" is called

msaps commented 6 years ago

@salvasp I'll take a look! Reuse / improved insertion is high on the list for Pageboy 3, so hopefully will get to start working on it shortly 😄