tags:

views:

23

answers:

1

I have a project where where i have one ViewController and two xib files. I have two buttons on a view which is shown in the viewcontroller. Both buttons are active and returning a NSLog so i know they are working. Basically I would like to load a xib when the button is pressed. I have a view setup in each xib.

Thanks for your help in advance!

A: 

Send [[NSBundle mainBundle] loadNibNamed: @"MyXib" owner: self options: nil] from your view controller. When the xib gets loaded the view controller will connect its Interface Builder outlets as specified in the xib. Make sure that in IB you've set the class of File Owner to your view controller's class and connected the outlets you need.

Costique
Thanks i am quite new to xcode so i might be doing something wrong. In my button action i have the following code: is this all i need to load the nib?
[[NSBundle mainBundle] loadNibNamed: @"playGame" owner: self options: nil] ;
Yes, that should do it. You may also want to check the return value of loadNibNamed... to make sure the the nib has been loaded. Oh, and after the nib loads, you may want to add the views loaded from the nib to the view hierarchy like this: [bigView addSubview: loadedView].
Costique
Thanks very much that was very useful