views:

538

answers:

2

Hey there,

I'm fairly new at this, but I think what I'm looking to do makes sense. I have a xib that is displayed in portrait and one that is displayed in landscape. Both views are similar, but have a few differences. Some of the buttons, labels and textfields are the same.

I can reveal one and hide the other when the orientation is changed - that's not the problem.

Basically I'm looking to have one place where I can handle all of the common button click responses or text changes. When a user is in portrait mode and enters text or selects a button, then they change to landscape mode the corresponding buttons and text will be updated.

I tried adding an NSObject in interface builder and assigning it to a new class that has outlets and actions for the buttons and textfields, but when I interact with a button I get an "unrecognized selector sent to instance" error in xcode.

Any help would be great.

Best, Ward

+1  A: 

Don't forget that xibs aren't templates — they are freeze-dried objects. A button in one has no connection to a button in the other.

David Dunham
+1  A: 

Objects you add in Interface Builder are instantiated when the XIB loads, you cannot have the same object in multiple XIBs.

What you use to connect multiple XIBs is the "File's Owner" object you see in each XIB. When you load a XIB using [NSBundle loadNibNamed:@"myXIB" owner:self] then what you pass in as owner object is ending up as the File's Owner in the loaded XIB and Cocoa will connect the IBOutlets and IBActions you have in it (be sure to set the proper class of the File's Owner object in Interface Builder).

So then you could make the controller object of your landscape view the owner of the portrait view XIB and put all IBActions in that controller, where they will be accessible from both XIBs (through the controller in one and through the File's Owner in the other).

Adrian