3

I am using core data, with an up-to-date XCode. I have a table, view-based, with NSPopupButtons in one of the columns. The table has an array controller that gets its data from entity A. There is another array controller for entity B. It is this entity B that should fill the popup button items.

An NSPopupButton outside a table can be filled without a problem, so this must be a table-related issue!

How should I fill the popup button that's within a column in my table?

Part of the table, with the Popup Button in place.

Carelinkz
  • 936
  • 8
  • 27
  • Have you looked into subclassing NSTableViewCell? – Nate Chandler Dec 23 '12 at 19:56
  • No I have not. That might do the trick, but is this really the way I should proceed? A Popup within a cell seems like a prime reason to use view-based tables, so I prefer to stay away from subclassing as long as I can :-) – Carelinkz Dec 23 '12 at 21:36
  • 1
    Another possibility is to use NSPopUpButtonCell. This, however, may not have quite the appearance you're hoping for. – Nate Chandler Dec 23 '12 at 22:14
  • 1
    The NSTableCellView documentation states "The NSTableCellView class is a reusable container view shown for a particular cell in an NSTableView instance that uses rows for content. The imageView and textField properties are connected in Interface Builder. Additional properties can be added by subclassing NSTableCellView and adding the required properties and connecting them programmatically or in Interface Builder." – Nate Chandler Dec 23 '12 at 22:18
  • Ah, right you are. That's a pity, I was hoping for a quick binding solution. – Carelinkz Dec 23 '12 at 23:05
  • I'm not sure I understand the problem. Why are you using a view-based table view? Why can't you bind the cell's `contentValues` binding? – paulmelnikow Dec 27 '12 at 01:21
  • I am not very experienced with tables but my understanding is that especially with a view-based table, it should be easier to put stuff other than bare-basics (such as popups) in the cells . And I did try to bind the contentValues, but that somehow did not work. Am I doing something wrong here? (i.e., _should_ it work?) – Carelinkz Dec 27 '12 at 19:01

3 Answers3

0

You could do the following:

  1. Increase the row height of the table view to 22px or greater.
  2. Bind to objectValue.menuValues (obviously something you add to your objectValue).
  3. The NSPopupButton should be placed as a subview of the NSTableCellView.

This way, as long as your objectValue has a binding able to populate a NSPopupButton's menu, you don't need to directly access it. From here you could also set the selector outlet to your delegate/view controller's class and use some nifty superview digging to find the NSTableCellView holding it, and operate from there.

It's complex, I know, but it's pretty much zero code. Once upon a time, I used to look down upon IB for being too "n00b", but Bindings make it quite a powerful tool.

Aditya Vaidyam
  • 6,259
  • 3
  • 24
  • 26
  • Thank you for the suggestion! I will look at this as soon as I get a chance, hopefully on Monday. – Carelinkz Mar 16 '13 at 11:24
  • No problems, I'm interested in seeing how this works out for you. – Aditya Vaidyam Mar 16 '13 at 17:08
  • Apologies, after a major UI overhaul this issue is no longer present in my project, and unfortunately I can not check out your suggestion in an easy manner. I do think I will come across this problem at a later time, and I'll be sure to report on my results! – Carelinkz Mar 26 '13 at 14:52
0

I have certainly had cell based NSPopupButtonCell working find. You should be able to achieve the same with view based tables. The binds are quite different as you bind directly to the objects in the view. So bind your popup's content directly to the data source. Create an ArrayController in IB for entity B and bind this to the Popups Content directly, also bind the contentValue to the entity B's field you want to display.

Then bind the popup's Column Content to entity A and now bind the popup's Value to Table Cell View objectValue.(entity A field name).

Duncan Groenewald
  • 8,496
  • 6
  • 41
  • 76
0

It is necessary to pass the controller through Files' Owner instead of binding it directly to the popup button. (Some say, it is a bug in Xcode..)

So, my solution uses an IBOutlet (currencyCtrl) in File's Owner, which is bound to the array controller (in your case for entity B). For the NSPopupButton, you should use this bindings:

enter image description here