Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add new pages to a UIPageViewController after the user has reached the last page?

I have a UIPageViewController that contains view controllers that are instantiated from data fetched over the network. When the user is paging and gets within a few pages of the end, I kick off a new network operation and put the resulting new view controllers onto the end of my UIPageViewControllerDataSource's mutable array of view controllers. In general this all works pretty well.

But if the network is slow (or the user is fast), it's possible to reach the final page before the network operation has completed. Since pageViewController:viewControllerAfterViewController: gets called when the user reaches the last page, it has already returned nil ("to indicate that there is no next view controller").

Is there a good way to force the UIPageViewController to call pageViewController:viewControllerAfterViewController: again (so that when the network operation completes and there are now new pages, I can force this call so the user can page to the new pages)? Or is there a workaround (maybe preventing the user from paging to the last page, but still showing the bounce animation)?

like image 385
Kevin L. Avatar asked Mar 09 '13 01:03

Kevin L.


1 Answers

See here: Refresh UIPageViewController - reorder pages and add new pages

When you get your data back from the network, call setViewControllers: direction: animated: completion: and set the current view to the current one again. That forces it to re-call pageViewController:viewControllerAfterViewController:

like image 117
ssloan Avatar answered Oct 06 '22 05:10

ssloan