Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SetAction for NSPopUpButton is disabling my popUpButton

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?

like image 348
Akbar Avatar asked Mar 07 '12 11:03

Akbar


1 Answers

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.

like image 155
petert Avatar answered Sep 17 '22 12:09

petert