Using a xib file without initializing a view controller
I'd like to use IB to create a toolbar with assorted toolbar items, but create and use this toolbar programatically - adding it to a view at my 开发者_JS百科discretion, and not while initializing the view controller.
I'm pretty sure it can be done - but haven't been able to find a good reference. Any help?
Read about NSBundle's loadNibNamed:owner:options:
method:
NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"Toolbar" owner:self options:nil];
This will return all the objects in nib which you can get using simple array methods. Also note that if nib file references any outlets to other objects in nib - they must be defined in your controller (or any other given nib owner) as well otherwise you'll get KVC exceptions.
精彩评论