English 中文(简体)
Multiple Xib files - Same Class
原标题:

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

问题回答

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).

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.





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签