Reputation: 32217
If I do an interface in IB
must I always need a base UIViewController
or can I just skip straight to a UIView
?
As of now I'm doing all my design in obj-c
which makes for a bit more busy work.
If I have to use a UIViewController
is there anyway to suck the UIView
out of it if that's all I want?
I just want to be able to pull out static layouts from XIB
instead of putting them together in obj-c
.
Any suggestions are appreciated!
Upvotes: 4
Views: 568
Reputation: 104698
No, you don't need to associate a UIViewController
with a XIB.
First, do not add a view controller to the XIB. Then, you'd often use NSNib
or UINib
APIs to access the top level objects of the nib -- so you can avoid a view controller and set up any structure you'd like in the NIB editor, and programmatically access the objects in the NIB as needed.
Upvotes: 1
Reputation: 8808
No, you don't need a UIViewController if it doesn't serve your needs.
After you have initialized a UINib, use its:
-instantiateWithOwner:options:
to access the nib contents. Make the nib's root object be a UIView (or subclass thereof). If you plan on making connections to File's Owner you will need to set File's Owner to a context-appropriate class.
Upvotes: 1
Reputation: 89509
UIViewController
has that handy initWithNib: bundle:
method that makes everything so easy, but there are also ways to get objects from xibs via:
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"WhateverItsNamed" owner:self options:nil];
(and the nib array here contains objects which correspond to whatever objects are stored in the XIB file).
Upvotes: 1
Reputation: 563
In iOS 5, XIB are not recommended to be used anymore, you should use a storyboard instead. And to simply answer your question, every top level view requires a view controller to be responsible for it.
All sub views can be an outlet in your view controller and be handled from there.
Upvotes: 0