I’m trying to add some items to a NSPopUpButton during runtime, but I cannot make any modifications to it, I can only read values.
(part of) my code:
@interface GAH : NSObject {
// ...
IBOutlet NSPopUpButton *popper;
// ...
}
@end
and then my @implementation:
@implementation GAH
// ...
-(void)someMethod {
// in a for loop
NSString *name = @"a name from the loop";
[popper addItemWithTitle:name];
// end for loop
NSLog(@"items: %d", [popper numberOfItems];
}
The last line returns 0 even though the addItemWithTitle gets called multiple times (i made sure the name is set correctly)
The following is also a sign of it’s “read-only”
[popper setAutoenablesItems:YES];
NSLog(@"%@", [popper isAutoenablesItems] ? @"YES": @"NO");
// Prints "NO"
Am I missing something to the IBOutlet declaration?
Is
NSPopUpButtoneven initialized when you are calling it? Anilobject will no-op. At no point in your code are you checking if it isnilor not. I’d put a log statement to see ifpopperisnil. If it is, make sure it is connected in your nib.