问题
I am using view based NSTableViews that is populated using bindings and array controllers with core data. Everything works great--cells with text and buttons and cells with image and text--I can edit the text as well, etc.
What I can't figure out and have searched everywhere is how to populate the popup menu. There are 2 array controllers, one for table view and one for popup buttons menu items.
I have tried binding the popup menu the classic way: by binding content (arrangedObjects to entity Place), content values (arrangedObjects Place.name), and selected object (Table Cell View objectValue.places.name.
Shouldn't all the controls should work like normal controls in view based tableviews? The menu is not getting populated. However, if the tableView's entity already has a value/relation set the value is being shown correctly.
Any help would be super. Thanks, Dan
回答1:
I think there is a bug here, I faced exactly the same problem. Here's my work-around:
Instead of binding the pop-up button directly to the Array Controller in IB, I put an outlet (named arrayController) in my nib's File's Owner to the NSArrayController
and bound the pop-up button like this:
回答2:
check this out:
https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaBindings/Tasks/onerelation.html
http://www.tbef.se/blog/2006/08/31/core-data-bindings-nstableview-and-nspopupbuttoncell/
CHECK that only 3 params were set!!
Content
Bind to: LanguagesArrayController
Controller Key: arrangedObjects
Model Key Path:
Content Values
Bind to: LangsArrayController
Controller Key: arrangedObjects
Model Key Path: name
Selected object
Bind to: CoursesArrayController
Controller Key: arrangedObjects
Model Key Path: language
来源:https://stackoverflow.com/questions/10768492/how-to-populate-nspopupbutton-from-coredata-in-view-based-nstableview