Billy Pilgrim
Billy Pilgrim

Reputation: 1852

Single View controller with multiple nibs?

I am trying to construct a view controller that can be 'skinned' -- that is, have multiple appearances or personalities but that uses a single controller. Each view will have the same buttons, etc, but I would like to be able to load each nib file (skin) into the same view controller. I can create multiple nib files, but I don't see how to connect the buttons, and actions. Can I specify the same 'file's owner' for multiple nib files? (HOW?).

Can this be done?

Upvotes: 8

Views: 4733

Answers (2)

Fonix
Fonix

Reputation: 11597

you can do it much easier if you literally copy and paste the view inside the nib file into the same nib file, so that you have 2 separate views inside 1 nib file.

example pic

then you can swap between the views as you load the nib like so:

NSArray *temp = [[NSBundle mainBundle] loadNibNamed:@"Widget" owner:self options:nil];
Widget *w = [temp objectAtIndex:0]]; // or 1 or 2 etc to get the different views

this will copy all your button connections etc, so you can just fiddle around with the copy without having to setup everything again

Upvotes: 0

theChrisKent
theChrisKent

Reputation: 15099

This is totally possible. Just create new nib files and in Interface Builder set the file owner to the class. You can then hook up your outlets and actions just like before. From your code just specify the correct nib file in the initWithNibName: method.

If the only changes are cosmetic, you might be better off just making those changes in code, but your proposed method will work just fine.

Upvotes: 8

Related Questions