I'm opening a new question to followup on my last one (http://stackoverflow.com/questions/2064513/superview-and-parentviewcontroller-nil-after-adding-a-subview). Basically I get that using subviews is a good idea, but that I shouldn't have a ViewController controlling a subview that lives inside another ViewController. Basically I'd like to do the following... I have two ViewControllers which share a common subview. I've created that subview as a nib called SearchDate.xib. The file owner is a corresponding class SearchDateView.m/h. That class has an outlet for the only element inside the UIView in the nib which is a label. The SearchDateView class also has a function for changing the value of the label in the SearchDateView.xib. I'd like both of my ViewControllers to load this nib but apparently I have no idea how to properly load the nib. No matter what I do at best nothing displays and at worst an exception is thrown. The apple docs talk about dragging in other instances of classes in IB right into your main view but that seems not to be working out. I have a SearchDateView outlet in my ViewController and I tried doing this on the controller's load view:
searchDateView = [[[NSBundle mainBundle] loadNibNamed:@"SearchDateView" owner:self options:nil] objectAtIndex:0];
[[self view] addSubview:searchDateView];
But I get this exception:
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<MainViewController 0x431fac0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key searchDateLabel.'
I know I'm doing something totally wrong but what is the right way to have a nib, associated view class which updates some of the objects in that nib, and reuse that nib in different controllers?
EDIT: Given the comment perhaps this wasn't clear enough. I don't want to use the same nib file for an ENTIRE view - rather a subview. So for instance controller A has a map and also a SearchDateView, and controller B has a table view and a SearchDateView. So I'm wondering how to load a subview into multiple controllers...