views:

227

answers:

1

I have a XIB set up like in this screenshot:

alt text

File's owner is my main window controller. The XIB is also in charge of creating an object that serves as the delegate for the MGScopeBar view. As you can see in the screenshot, the scope bar delegate has an IBOutlet for the search field so that it can return it as an extra view as part of the delegate process.

The problem I'm having is that when the delegate object is queried for the accessory view, the IBOutlet NSSearchField is nil. I'm fairly certain this has something to do with the order that objects are created, IBOutlets wired, etc, but I'm just a little lost as to where in the process I can expect the search field to exist so that the scope bar delegate can reference it properly.

Thanks in advance for any pointers.

+1  A: 

Per Apple's documentation, it looks like all of the outlets in a NIB/XIB are supposed to be wired before awakeFromNib is called on any object in that NIB/XIB, but that outlets probably are not wired when init, etc., are called on the objects.

Isaac
No “probably” about it. Outlets are set via KVC (iPhone) or behavior very much like it (Mac). That can only happen *after* the object has been allocated *and* initialized. Think about how you might do it if you were implementing the nib loader; it'd be something like: `id instance = [[[objectClass alloc] initWithCoder:unarchiver] autorelease]; for (NSString *k in objectOutlets) [instance setValue:[objectOutlets objectForKey:k] forKey:k]; [instance awakeFromNib];` Notice that `initWithCoder:` returns before outlet-setting begins; no outlets are set yet while `initWithCoder:` is running.
Peter Hosey