views:

278

answers:

2

I have an NSPopUpButtonCell inside a custom NSCell and I'm using

- (BOOL)startTrackingAt:(NSPoint)startPoint inView:(NSView *)controlView

to produce the pop up menu when it's clicked.

I have also overridden copyWithZone: in my custom cell to copy the popUpCell instance variable so that each row in my table view has its own pop up cell.

My problem is that although the menu pops up just fine, and you can select an item from the menu, when an item is selected the cell does not change its selected item to match the chosen one from the menu.

However, if I comment out the line in copy with zone which copies the cell, then it behaves properly as far as selection goes (changing to match the selected item, although every single row will then have that same selected item).

Does anybody know why this is, or more to the point, how I can fix it?

A: 

Have you tried using

–trackMouse:inRect:ofView:untilMouseUp:

instead of

startTrackingAt:inView:

?

Diederik Hoogenboom
A: 

I'd suggest not copying the cell and instead using the:

- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex

...delegate method to set up the cell with the correct data before each row is drawn.

grahamparks
What I'm actually doing is using bindings with an NSArrayController, which seems to make a copy of the single cell from time to time. I'm not manually calling [cell copy] myself at any point.
Lawrence Johnston