Page Controls, ScrollViews, and Storyboarded Scenes
So here I am implementing paging into my app. I’ve laid out what each of the pages should look like by designing them in the storyboard and I made the subclassed view controllers for each of them. No problem. Everything looks great. I proceed to load the scroll view with my page’s view controllers and I’m ready to run. I switch on the simulator and see… nothing. Blank. Empty. What?
As it turns out, attempting to instantiate the view controllers normally means that the associated view is blank. The correct way to instantiate a storyboarded view controller (with its proper view) is to do the following:
- For each scene that you want to use as a page, go to the Attributes Inspector and give each scene a proper Identifier. For example, I’ll call my scene “My Page Name”.
- Instantiate the view controller from the storyboard reference instead of the traditional alloc-init.
MyViewController * page = [self.storyboard instantiateViewControllerWithIdentifier:@"My Page Name"];
With that small change, the scene will be properly rendered. While this problem may not be exclusive to paging, I find that this case is where the problem is most likely to show up.