XIB-instantiated Object's IBOutlet is nil

2019-08-15 02:44发布

问题:

I have a XIB set up like in this screenshot:

alt text http://emberapp.com/jxpx777/images/interface-builder/sizes/m.png

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:

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.