Re: Questions about NSPopupButtonCell and NSBrowser
Re: Questions about NSPopupButtonCell and NSBrowser
- Subject: Re: Questions about NSPopupButtonCell and NSBrowser
- From: "Frank D. Engel, Jr." <email@hidden>
- Date: Sun, 19 Jul 2015 15:00:00 -0400
In case anyone else is struggling with popup button cells like I was, I
did finally get this to work - though the solution looks a bit strange
it definitely seems to be giving me the behavior I wanted.
Short version: there are two entities defined (Core Data) and there is a
one-to-many relationship between them: for sake of explanation, lets
call them "Folder" and "File" - where each "File" is in one "Folder" but
there can be multiple files in a folder.
A third entity had a reference to Files, and I wanted an NSTableView to
list the records of that third entity, call it "X", but I wanted two
popup button cells for selecting the Files - one to choose a Folder, and
the other listing the Files inside of it.
The way I finally got this working:
In the custom subclass of NSManagedObject for entity "X", I implemented
"folder" and "setFolder" methods; "folder" returns the "folder" of the
"File" that is referenced by "X", and "setFolder" effectively picks an
arbitrary "File" from the indicated "Folder" and sets "X" to point there.
In the custom subclass of NSManagedObject for entity "Folder", I
implemented "arrangedFiles", which returns a sorted NSArray of the files
in the folder (the actual relationship returns an NSSet and I needed an
NSArray - plus I wanted it sorted a specific way).
In the XIB file, I have an NSArrayController for the set of all Folder
records - call it "Folders" - and another one for the set of records in
X - call it "Xrecs" (I am making up these names).
The File and Folder entities both have "name" attributes for display.
My bindings for the NSPopupButtonCells are:
For the Folders one:
Content - Folders.arrangedObjects
Content Values - Folders.arrangedObjects.name
Selected Object - Xrecs.arrangedObjects.folder
For the Files one:
Content - Xrecs.arrangedObjects.folder.arrangedFiles
Content Values - Xrecs.arrangedObjects.folder.arrangedFiles.name
Selected Object - Xrecs.arrangedObjects.file
It seems a bit weird to me to specify a record attribute of an array
(arrangedFiles.name), but it occurred to me that this was how the other
ones look with arrangedObjects, so I gave it a try and it seems to work
just fine.
Hope someone finds this helpful.
_______________________________________________
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