I am using the example from this question: How to combine UIScrollview with UIPagecontrol to show different views? to add a UIScrollView
containing multiple subviews to a page in my iPad app.
My app has one large view at the top then a small box at the bottom. The box at the bottom is the UIScrollView; the user will swipe left and right to bring up boxes for various functions in that small section. The large view at the top never changes, so I don't think segues are appropriate.
I have a storyboard with a single View Controller Scene in it. While I can add views to this I can't design 'off screen' views; in other words, there's nowhere I can draw each of my subviews. How can I do this? Do I need to make separate XIBs for each subview? If so, how do I load them in? Or, should I instead make my scrollview (subview width * subview count
) wide and draw each view adjacent to the previous one? This is my first iOS app so I may well have some things backwards.
Thanks
Tim
Currently storyboards are not ideal for doing this however you should not use separate nib files. Instead you should pull on other viewControllers and setup each of their views as required. You must remember to set the identifier of the view controller in interface builder and then you can load the view like so,
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; UIViewController *myViewController = [storyboard instantiateViewControllerWithIdentifier:@"MyViewControllerIdentifierInIB"];
Now you have the view controller you can get access to the view and add it wherever you would like.
Note: To change the size of your view you will have to select the view controller and change its Size in the attribute inspector in interface builder to freeform. Then you will be able to change the size of the view.
I also found that, but eventually you lose the purpose of storyboarding which is to present you with the full-flow of your graphical application.
What I really feel lacking here is a new cocoa object i.e. UIPagedScrollController that when added to the storyboard would have it's own segue transition similar to UIToolBarController and UINavigationController but would be comprised of both the UIPageControl and UIScrollView needed to make the magic.
I eventually found that I could create the subviews in separate NIBs. In the subview NIBs I set File's Owner's identity to my main view controller's class and add an outlet to the view controller for the subview. I then link the subview in the NIB to that outlet in File's Owner.
Finally in the main view controller's viewDidLoad
I call this for each subview NIB:
[[NSBundle mainBundle] loadNibNamed:@"MySubView" owner:self options:nil];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With