iPad - UIPageViewController - “dequeueReusableCellWithIdentifier” kind of option

StackOverflow https://stackoverflow.com/questions/7874892

  •  11-02-2021
  •  | 
  •  

Pregunta

I'm creating an app to show a book by using UIPageViewController (to have the default page turn animation which is very nice) I'm maintaining all the data related to each page in form of core data. In my MyModelController.m file, under init method, I'm fetching all the data and initializing pageData array. But the book that I'm going to show is huge one. So, is there any way to do something like dequeueReusableCellWithIdentifier so that only required pages will be loaded into memory?

Please correct me if my expectation is wrong.

¿Fue útil?

Solución

Set the initial view controller using UIPageViewController's

-setViewControllers:direction:animated:completion:

Next, implement he following UIPageViewControllerDataSource methods:

– pageViewController:viewControllerBeforeViewController:
– pageViewController:viewControllerAfterViewController:

These methods allow you to provide the UIPageViewController with the view controllers before and after the current view controller.

This way you only keep a single view controller (and corresponding model data) in memory. I'm sure it does some caching behind the scenes, but if so, that would be freed when a low memory warning was triggered.

Instead of loading your entire data model in a single array, load only the required objects for the current view controller on-demand page-by-page inside your view controller representing a single page, or inside the two datasource methods mentioned above.

If you create an new UIPageViewController-based project in Xcode 4.2, you will see the default template has code demonstrating this.

Otros consejos

Correct me if I'm mistaken, but I believe UIPageViewController, by default, only loads the next and previous page into the memory, so you shouldn't have to worry about memory management.

Not positive I understand your question, but it sounds like you don't want to have all of the content of your book loaded as page objects. Instead of loading the entire contents of the book in your init method only load the page being displayed, then when the user "turns" the page load the next, or previous, page based on the currently displayed page.

If you are using a PDF book, you can only load the desired page and pass to the view controller when these two methods are called

– pageViewController:viewControllerBeforeViewController:
– pageViewController:viewControllerAfterViewController:
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top