Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
311 views
in Technique[技术] by (71.8m points)

ios - Refresh UIPageViewController - reorder pages and add new pages

I have a UIPageViewController which I am providing page data for using an implementation of UIPageControllerDelegate and UIPageControllerDataSource.

It's all working fine, but I want to be able to add items to the page data and reorder the page data.

If a user has already got to the last of the pages, and then I add an item, they can't get to the next page because viewControllerAfterViewController: has already been called. If they scroll back one and then forward two they can get to the new page fine, so the data is setup correctly. How can I tell the UIPageViewController to refresh its store of what comes next?

Similarly I would like to reorder the collection that is backing the page view. But if I do this I'll get the same problem - the page view will think the next page is still what it was last time the current page was loaded.

I guess I'm looking for something similar to reloadData: on UITableView.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I found a workaround to force UIPageViewController to forget about cached view controllers of neighboring pages that are currently not displayed:

pageViewController.dataSource = nil;
pageViewController.dataSource = self;

I do this everytime I change the set of pages. Of course this doesn't affect the currently displayed page.

With this workaround I avoid the caching bug and can still use animated:YES in setViewControllers:direction:animated:completion:.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...