Re: NSMenu in NSTableView column
Re: NSMenu in NSTableView column
- Subject: Re: NSMenu in NSTableView column
- From: Keary Suska <email@hidden>
- Date: Tue, 12 Aug 2014 18:34:12 -0600
On Aug 12, 2014, at 12:14 PM, Jonathan Taylor <email@hidden> wrote:
>>>> 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.
>>
>> Ah ok, I've revisited that and got it to work. I'd tried it before and it had had no effect; I'd assumed that was something else that just didn't work with tables. However I've now spotted the compile-time warning about only sending actions to the table view delegate, and after fixing that it works nicely. Thanks very much.
>> Jonny
>
> Actually, I'm not sure that solves my problem as easily as I thought. I'll just restate what I'm trying to achieve to make sure I'm being clear, and then explain the difficulty I'm having in making it work.
>
> Each menu item string is a user-readable description of a signal channel, each is associated with a numerical channel ID. However there isn't a natural and obvious relationship between the index of the menu item and the channel ID. It seems sensible to me to have the menu item strings defined in the same place as the numerical IDs. I can imagine two ways of doing this:
>
> 1. Define the menu item strings in InterfaceBuilder as menu items, and give each one a tag representing the channel ID. This is what I have been trying to do, but I can't work out how my code should identify the tag associated with the menu item index (which is what I get in my NSArray representing the current state of the table). I can put an action on the menu item, but at the time that is called I don't know which row's menu has just been selected. Also (rather unexpectedly), putting an action on the menu item seems to prevent the "selected index" binding of the popup cell from being updated.
>
> 2. Define the menu item strings and associated channel IDs in my code, and use bindings to populate the menu items. I did try that, but haven't managed to get my strings showing up in the menu. Can anyone recommend clear instructions for making that work? I think I maybe don't properly understand the difference between content values and content, and what exactly they need to be bound to...
>
> Any thoughts about how to make either of these work?
I would create a class, say, SignalChannel, with "name" (for description, but we may not ant to use "description" for obvious reasons...) and "channelID" properties. I would then populate the NSPopupButtonCell with SignalChannel objects. This will abstract the model from the view, which is better form anyway.
HTH,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden