Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

controller reload datatsource #205

Open
Chepond opened this issue Nov 12, 2018 · 1 comment
Open

controller reload datatsource #205

Chepond opened this issue Nov 12, 2018 · 1 comment

Comments

@Chepond
Copy link

Chepond commented Nov 12, 2018

how to reload the datasource of controller?
for example if i added more galleryItems to the array upon paging, how do i reload the whole source? since if i add the source to the start of array, it is working(direction: left), but if i add to the last of the array, it is not able to swipe to next photo(direction: right)

@Chepond
Copy link
Author

Chepond commented Nov 12, 2018

I have found the root cause.:)
When I added source to the start of array, after I called page(to: index), it can go to the last galleryItem as the index of the last galleryItem after paging has changed(increased). But if I add source to the end of array, the index of the last galleryItem will remain unchanged, then the page function will not perform any action as it is guarded....

Can anyone please give me some hope, any WORKAROUND around?:(
Or can you add the reload data source function plssssss

open func page(toIndex index: Int) {

    guard currentIndex != index && index >= 0 && index < self.itemsDataSource.itemCount() else { return }

    let imageViewController = self.pagingDataSource.createItemController(index)
    let direction: UIPageViewController.NavigationDirection = index > currentIndex ? .forward : .reverse

    // workaround to make UIPageViewController happy
    if direction == .forward {
        let previousVC = self.pagingDataSource.createItemController(index - 1)
        setViewControllers([previousVC], direction: direction, animated: true, completion: { finished in
            DispatchQueue.main.async(execute: { [weak self] in
                self?.setViewControllers([imageViewController], direction: direction, animated: false, completion: nil)
                })
        })
    } else {
        let nextVC = self.pagingDataSource.createItemController(index + 1)
        setViewControllers([nextVC], direction: direction, animated: true, completion: { finished in
            DispatchQueue.main.async(execute: { [weak self] in
                self?.setViewControllers([imageViewController], direction: direction, animated: false, completion: nil)
                })
        })
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant