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.
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.