简体   繁体   中英

NSPopupButton within a view-based NSTableView

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?

表的一部分,弹出按钮就位。

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.

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).

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:

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM