views:

142

answers:

1

I've created a custom subclass of NSCell with an NSImageCell, some NSTextFieldCells, and an NSPopUpButtonCell.

I'm initializing the pop up cell using:

    myPopUpCell = [[NSPopUpButtonCell alloc] init];
    [myPopUpCell setBordered:NO];
    [myPopUpCell setAutoenablesItems:NO];
    [myPopUpCell addItemsWithTitles:[NSArray arrayWithObjects:@"Item1", @"Item2", @"Item3"]];

And drawing it in drawInteriorWithFrame:inView:

Everything seems to work great, except that when clicking on the pop up cell while running my app the cell does not pop up. Any suggestions about what might be wrong?

+5  A: 

Drawing the pop-up button cell in drawInteriorWithFrame:inView: is going to do just that; draw it, but nothing else. Handling click events is unrelated to drawing, so you're going to have to do some work in your custom cell to interpret mouse events, and if they're inside the frame you're using for the pop-up button, pass them on to the button cell. Start by subclassing the methods listed in the NSCell docs under tracking the mouse, such as –trackMouse:inRect:ofView:untilMouseUp:, and you should be be able to figure out what's needed to make the button cell act correctly.

Depending on what you're doing you may actually find it easier to draw the title string yourself, and just use NSMenu's +popUpContextMenu:withEvent:forView:.

Marc Charbonneau