Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

tmeehan

macrumors newbie
Original poster
Feb 25, 2009
12
0
I've got a two column tableview - column 0 is text, column 1 is popupcells. Everything seems fine but when I release the mouse when selecting from the popup, it momentarily displays the selection i made but it then resets back to item 0 (first item) in the menu list. I've gone over this million times. In my datasource class I have the 3 required routines. It all comes down to the fact that I can't get the selected item index - it always returns 0.

In the routine:
-(id)tableView: (NSTableView *) tableView objectValueForTableColumn:(NSTableColumn *) tableColumn row: (int) row

I do the following:
selection = [[tableColumn dataCell] indexOfSelectedItem];

this always returns 0. I have verified that I do indeed have the correct datacell by verifying it's itemArray. Everything checks out but the "indexOfSelectedItem" method always returns 0.

I manually set the returned value to "2" just to see if the pop up would get set to the third item - It does. I just can't get the dataCell to tell me what item is selected.

And then down in the other routine:

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

if I manually set the value to 2 for example, my popup changes correctly. I am going nuts!

I am unsure of a couple of things; for a popup control in a listview, am I supposed to use the "setObjectValue" method or should the popupbuttoncell class take care of maintaining the currently displayed item?

For the text column, I am storing the values in an NSMutableArray. That's all working fine. But when my datasource is asked for the value of the popupmenu, i assume I have to return the current item index. If I manually return a value it responds correctly - but like I have said numerous times - i don't seem to be able to query the datacell for its currently selected index.

It's almost as if internally a copy of my datacell is being used but it is not a complete copy. It has all the right menuitems in it but for some reason it can't provide the currently selected item index.

All and all help with this would be greatly appreciated.

Thanks
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
When the popup selection changes, it will call back tableView:setObjectValue:forTableColumn:row: - the objectValue is what you want. This will be an NSNumber containing the index of the selected item. You will then need to update your data to hold this value, so that next time it updates in tableView:eek:bjectValueForTableColumn:row: it will use this value. And yes, in that method return an NSNumber containing the index of the item you want selected. If you want finer control, you can implement the tableView:willDisplayCell:forTableColumn:row: method.
 

tmeehan

macrumors newbie
Original poster
Feb 25, 2009
12
0
NSPopUpButtonCell

Thanks for that reply. That made all the difference.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.