I’ve been into this issue for the past few days, I’d like to request your help.
I’ve a NSPopUpButton that I’d like to populate programmatically as the program is launched; on windowControllerDidLoadNib from a NSPersistentDocument subclass I’ve been trying to call interfaceReady (from MYOtherClass) as follows
- (void)windowControllerDidLoadNib:(NSWindowController *)windowController {
[super windowControllerDidLoadNib:windowController];
MYOtherClass *brain = [[MYOtherClass alloc] init];
[brain interfaceReady];
}
which is defined in MYOtherClass.m (btw it’s declared in .h) as follows
- (void)interfaceReady {
NSLog(@"HI %d",(int)[self.thepop numberOfItems]);
[self.thepop removeAllItems];
NSLog(@"HI %d",(int)[self.thepop numberOfItems]);
}
note these NSLog messages were added for Debug to see why it wasn’t working; in the Console both messages show a 0 (the removeAllItems does not change the popup). Am I firing the event too early? Doing something wrong? Please let me know.
Thank you for your time.
Note: I’ve tried adding a debug button to the interface (wired to a IBAction method) to “manually” populate the popup and it worked, so I guess it’s wired up properly in interface builder. I still don’t know why the above doesn’t work though.
The problem is that the MYOtherClass instance,
brain, which you are instantiating, has no connection to the nib. If the nib contains a MYOtherClass instance, this is not that instance. If the nib contains no MYOtherClass instance, then there is no way that any MYOtherClass instance can see the popup menu via an ivar.The usual candidate for an ivar matching an outlet in the nib is the File’s Owner proxy (because this is a readily identifiable instance known to exist independently before the nib loads). In this case, the File’s Owner is probably the window controller itself.