On Aug 12, 2014, at 6:14 AM, Jonathan Taylor <jonathan.tay...@glasgow.ac.uk> 
wrote:

> I am trying to implement a popup menu in an NSTableView column. I seem to 
> have the bindings all set up so that the values in my NSArray are updated 
> according to the options the user selects in the table. However, I would like 
> to have some way of accessing the tag on the menu item that was selected for 
> each row. I thought I could wire up an outlet to the NSMenu object attached 
> to the table column, but when I later attempt to access the relevant menu 
> item in the menu (in order to look up its tag), I get the following runtime 
> error:
> 
>> -[NSMenu itemAtIndex:]: message sent to deallocated instance
> 
> I do not encounter this error if I bind to a standalone popup menu, so I 
> don't think I'm doing anything wildly stupid here. I can imagine that within 
> the table the popup menu objects are being dynamically allocated, so the 
> outlet plan isn't working out.

It's an "intuitive" mistake to made--I have made it a few times myself. It is 
not the case that there is a single menu for the column. In fact, there is a 
different NSPopupButtonCell for every row with (hopefully) a different NSMenu 
for each cell. If you construct it all in IB, this is what you get at run-time.

> My question then is how should I access the tags in the popup menu in order 
> to work out which tag corresponds to the selected item in each row? 

If I understand your setup correctly, the most direct route is to set an action 
on each menu item.

HTH,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to