I have created my NSPopUpButton programmatically with the following code
[myPopUpButton insertItemWithTitle:@"--Select one--" atIndex:0];
[myPopUpButton addItemsWithTitles:[NSArray arrayWithObjects:@"1.One",@"Two",@"Three", nil]];
[myPopUpButton sizeToFit];
[myPopUpButton setAction:@selector(popUpAction:)];
[fullBrowserView addSubview: myPopUpButton];
//PopUp Action
-(void)popUpAction:(id)sender
{
NSLog(@"popUpAction");
}
When I click the popUpButton,menu items of popUpButton are disabled. When I use interfacebuilder,just it is working fine with the IBAction.
Why this setAction is not working for NSPopUpButton?
Looks like you're not setting a target object to send the message to. So, in code, add:
[myPopUpButton setTarget:self];
assuming the popUpAction:
method is in the same class.
When you're using Interface Builder it's wiring-up the selector action to the target.
From the documentation for this call:
- (void)setTarget:(id)anObject
If anObject is
nil
but the control still has a valid action message assigned, the application follows the responder chain looking for an object that can respond to the message.
In your case, there is no object responding to the message.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With