1

I'm using a UIPageViewController as a way to swipe through the photos in a photo library. It works when photos exist, but crashes if no photos exist on the phone. The errors:

2015-04-19 16:27:05.305 MyApp[2566:1278254] *** Assertion failure in -[MyPageViewController queuingScrollView:didBailoutOfScrollAndRevealedView:], /SourceCache/UIKit/UIKit-3347.44/UIPageViewController.m:1903
2015-04-19 16:27:05.308 MyApp[2566:1278254] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'No view controller managing visible view (null)'

The data source delegate methods do return nil when no photos exist, so I would have thought that the page view controller would just show nothing. Obviously, that's incorrect.

What's the proper way to handle the case when there's currently no data to display in a UIPageViewController? Fabricate a dummy page content view controller and hand it off to the page view controller, just so it has something to display?

smeep
  • 332
  • 1
  • 17
  • If _no_ photos exist, then the delegate methods are not the problem: the problem is the _initial_ creation of the UIPageViewController, which has to be populated with an _initial_ page view controller. I'm guessing there is something wrong with your initial creation logic in the case where there is no data. – matt Apr 20 '15 at 00:06
  • Actually, I should have mentioned that the initial screen comes up just fine (with a blank view) -- although I'm not doing anything special when there's no photos. However, it crashes when you try to swipe either left or right. I've stepped through the code but can't yet figure out where it's failing. – smeep Apr 20 '15 at 03:51
  • If it crashes then your delegate methods are not right. You don't show any code at all so your question is pointless, since no one can help. – matt Apr 20 '15 at 04:08

2 Answers2

3

@matt was correct: the problem was that the initial page controller hadn't been set, which caused the crashing. Creating a dummy view controller did the trick:

[self.storyboard instantiateViewControllerWithIdentifier:@"NoPhotosViewController"];

smeep
  • 332
  • 1
  • 17
0

If your scroll style is UIPageViewControllerTransitionStyleScroll, then this your answer.

Community
  • 1
  • 1
Avi
  • 2,196
  • 18
  • 18