1

I'm using a UIPageViewController to present calendar-related content on a series of pages. For the month and year calendar pages, I'm using UICollectionViews, the cells of which contain a UILabel with the date number. The Year page uses a UILabel for each day of the year, so 365+ subviews.

I've found that when I manually scroll from other pages to the Month page, performance is acceptable, but scrolling to the Year page there is a big lag between when the user begins scrolling to it (this is when viewControllerBeforeViewController: is called), and when the page is actually displayed. The page is also choppy when scrolling, and is not nearly as responsive as other pages (which generally contain table views.)

My problem is that I can't feed the UIPageViewController a sequential array of view controllers for caching, since I often need to programatically jump from one page to another (meaning that I'm just setting up the UIPageViewController with a single view controller at any given time, using the solution in this answer: https://stackoverflow.com/a/17330606/1370967). Thus I rely on viewControllerBeforeViewController and viewControllerBeforeViewController to load pages when the user scrolls manually. (let me know if my understanding is off here).

So, I'm wondering how I can improve performance of loading and scrolling of the Month and Year pages.

Community
  • 1
  • 1
DivideByZer0
  • 745
  • 8
  • 26

1 Answers1

1

Try to print out view hierarchy for the content view of your UIPageViewController. When you feed it view controllers via viewControllerBeforeViewController and viewControllerAfterViewController it's essentially will have a scroll view containing three pages of content inside (one for previous, one for next and one for the current page).

If your view hierarchy contains more then 200 views (and from your description I think your total number of subviews will be around 500-600), I strongly recommend to redesign it differently. You will not get acceptable performance with such tree.

Aside from scrolling between pages if you ever need to adopt to device rotation you will have similar problems as well. Basically doing layout on such big number of subviews is complicated task and it will take time.

sha
  • 17,824
  • 5
  • 63
  • 98
  • It looks like the many views was definitely causing it. I created a grid for the day number labels in a separate UIView which wasn't added to any parent view, and used renderInContext: to create a UIImage out of that UIView, greatly reducing the number of subviews on the screen. It works very smoothly now! Thanks for the advice, and I'll cut down my question to make it more relevant. This answer helped me render it, by the way: http://stackoverflow.com/a/3495396/1370967 and this helped with blurriness: http://stackoverflow.com/a/11202715/1370967 – DivideByZer0 Sep 16 '14 at 06:53