views:

13

answers:

1

Assuming button1 is an NSPopUpButton Assuming menu attached to button1 is displayed and being tracked.

[[button1 cell] dismissPopUp] --- dismissPopUp is not recognized.

Why is the dismissPopUp method not recognized?

Thanks

A: 

Because NSCells don't respond to dismissPopUp messages.

If you're getting this as an exception at run time, make sure button1 really is a pop-up button—that is, make sure you hooked up that outlet to the right object in IB, or that you assigned the right object there if you created it in code. In the latter case, use the debugger to examine the variable.

If this is just a warning you're getting from the compiler, it's probably because cell is a method of NSControl (NSPopUpButton's grand-superclass), and is typed as returning an NSCell. The compiler has no way of knowing that this particular control will return an NSPopUpButtonCell. The solution is to assign the result of the cell message to a variable typed as NSPopUpButtonCell *, and then send the dismissPopUp message to the object in that variable:

NSPopUpButtonCell *cell1 = [button1 cell];
[cell1 dismissPopUp];

If you still get the warning, you'll need to add an explicit cast in front of the [button1 cell] expression.

Peter Hosey