Re: NSMenu in NSTableView column
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. Ah, I've worked out the underlying problem I've been having. I had been trying things along these lines and completely failing to get the popup menu to populate correctly. It was working for a standalone popup but not within the table, and I was assuming I was doing something wrong and/or it was more complex than I realised, and had basically decided not to continue stumbling around trying to make it work. Then I found this: http://stackoverflow.com/questions/14708947/nspopupbutton-in-view-based-nstableview-getting-bindings-to-work which describes what seems to be a bug in the implementation, along with the workaround (binding to an outlet property on the file's owner, rather than directly to the array controller). Weird. ___ 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
Re: NSMenu in NSTableView column
On Aug 13, 2014, at 4:04 AM, Jonathan Taylor jonathan.tay...@glasgow.ac.uk wrote: 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. Ah, I've worked out the underlying problem I've been having. I had been trying things along these lines and completely failing to get the popup menu to populate correctly. It was working for a standalone popup but not within the table, and I was assuming I was doing something wrong and/or it was more complex than I realised, and had basically decided not to continue stumbling around trying to make it work. Then I found this: http://stackoverflow.com/questions/14708947/nspopupbutton-in-view-based-nstableview-getting-bindings-to-work which describes what seems to be a bug in the implementation, along with the workaround (binding to an outlet property on the file's owner, rather than directly to the array controller). Weird. That link refers to a view-based table view, which is a different animal altogether. Is your table view cell or view based? It makes a big difference... 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
Re: NSMenu in NSTableView column
Ah, I've worked out the underlying problem I've been having. I had been trying things along these lines and completely failing to get the popup menu to populate correctly. It was working for a standalone popup but not within the table, and I was assuming I was doing something wrong and/or it was more complex than I realised, and had basically decided not to continue stumbling around trying to make it work. Then I found this: http://stackoverflow.com/questions/14708947/nspopupbutton-in-view-based-nstableview-getting-bindings-to-work which describes what seems to be a bug in the implementation, along with the workaround (binding to an outlet property on the file's owner, rather than directly to the array controller). Weird. That link refers to a view-based table view, which is a different animal altogether. Is your table view cell or view based? It makes a big difference... As it stands right now, it's view based (I switched it in InterfaceBuilder). Things seem to be working fine with that workaround. I started writing a long email to the list on the question of view- vs cell-based tables, but as is often the case, in the course of writing it I worked out the answer to my particular question at the time. I ended up with view based because Apple give clear instructions for how to bind things for them in Table View Programming Guide for Mac. Their advice for cell-based tables is rather unhelpful, just saying that it's very different and you should configure the column’s cell’s bindings. Well thanks Apple! Their instructions for view-based tables were clear, so I went with that. ___ 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
NSMenu in NSTableView column
Hi all, 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. 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? Thanks for any suggestions Jonny ___ 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
Re: NSMenu in NSTableView column
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
Re: NSMenu in NSTableView column
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 ___ 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
Re: NSMenu in NSTableView column
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? Cheers Jonny ___ 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
Re: NSMenu in NSTableView column
On Aug 12, 2014, at 12:14 PM, Jonathan Taylor jonathan.tay...@glasgow.ac.uk 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 (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