Let’s say, I have three UIViewController
- UserFormViewContoller
- NewUserFormViewController : UserFormViewController
- UpdateUserFormViewController : UserFormViewController
So, NewUserFormViewController and UpdateUserFormViewController view controller inherit from it’s parent to share the basic functionality. The different will be their method, create and update.
The views also have a lot of things in common, almost everything. The different view components between NewUserFormViewController and UpdateUserFormViewController is a button to perform save task (create or update)
Is it possible to have two UIViewController sharing one XIB file? Let’s say, UserFormViewController.xib and then I do
[[NewUserFormViewController alloc] initWithNibName@"UserFormViewController" bundle:nil];
[[UpdateUserFormViewController alloc] initWithNibName@"UserFormViewController" bundle:nil];
The other question but important is, when I edit xib file with Interface Builder, what owner’s reference outlets and IBActions is it talking about, NewUserFormViewController or UpdateUserFormViewController?
(IBActions and Outlets showing when we right click at the Placeholders -> File’s Owner)
If that’s so, I will just use one XIB file and programmatically add other specific view component (It would be great to have only one XIB file so that I can make some changes at a place but effective on both)
The “file owner” is just a convention so that XCode can show you the correct
IBOutlets andIBActions in its inspectors. If you create a generic (in OO terms: abstract)UserFormViewController(.h, .m, .xib), wire it in IB; then subclass it in twoNewUserFormViewControllerandUpdateUserFormViewController, they’ll inherit their outlets and actions from their parent class without any problem.