Re: Binding popup contents difficulties [SOLVED]
Re: Binding popup contents difficulties [SOLVED]
- Subject: Re: Binding popup contents difficulties [SOLVED]
- From: Ken Tozier <email@hidden>
- Date: Mon, 29 May 2006 15:43:09 -0400
Well here's one way to do it in case anyone else runs up against this
popup binding problem
(NOTE: The following assumes you have already created a nib file, a
window and placed a menu in the window)
XCode:
1. In the class you'll be using as the nib "files owner", define a
method that returns an array of strings to fill the menu with.
InterfaceBuilder:
1. Import the header for the file you are using as the nib's files
owner class
A. Select the classes tab of the nib file
B. In the "Classes" menu in the menu bar, choose the "Read files..."
command.
C. Find and select the header file for your files owner class.
D. Click OK and you'll see your class's name appear in the class
browser at the bottom.
2. Click the "Instances" tab and select the "File's Owner" object.
3. In the property inspector panel, choose the "Custom Class" item.
4. Select the class you just imported above from the list of
available classes.
5. Drag an NSArrayController from the "Cocoa-Controllers" tab of the
tools palette and rename it to reflect the purpose of your popup menu
6. With the array controller still selected, choose "Bindings" from
the inspector panel popup menu
7. In the "Controller Content" group, expand the triangle next to the
"contentArray" item and configure as follows.
A. in the "Bind to:" popup, select "File's owner" (Note it should be
appended with the name of your files owner class)
B. Ignore the "Controller key" field
C. In the "Model Key Path:" combo box, enter the name of the
accessor method you defined in XCode->1 above
8. Select the popup menu in your window you want to work with.
9. In the inspector panel, select "Bindings" from the popup menu.
10. In the "Value Selection" group, expand the triangle next to the
"contentValues" item and configure as follows
A. In the "Bind to:" popup, select the NSArrayController you created
(and optionally renamed) in step 5 above
B. In the "Controller Key:" combo box, select "arrangedObjects" from
the list.
C. Ignore the model Key Path field.
11. Save the nib file, Switch to XCode and build and run your project.
You should see your popup menu populated with the items supplied by
your "files owner" class accessor method.
If others on the list have alternative ways to do populate popup
buttons through bindings, post them, it could prove useful to others
Ken
On May 29, 2006, at 1:20 PM, Ken Tozier wrote:
Well,made a little progress, but now what's happening is that the
entire array appears as a single menu item.
I think there is something fundamental I'm not understanding about
binding and array controllers. The purpose of the accessor method
in the model class is to provide the entire contents of the array,
no? Unfortunately though this seems to mash the array into a single
item (like going [array description]) and placing this description
as the menu's sole item. How exactly are you supposed to fill a
menu? There's no mechanism to specify the model key path for items
within an array say like sites[#].
Please help almost 8 hours now trying to fill the contents of a
single menu. This is getting extremely frustrating.
Thanks
Ken
On May 29, 2006, at 10:06 AM, Ken Tozier wrote:
Still haven't figured it out yet but here's the most recent error
I'm getting
2006-05-29 09:48:39.668 QuarkXPress[2701] [<NSArrayController
0x117b9c10> addObserver:<NSSelectionBinder 0x117bfbf0>
forKeyPath:@"site.name" options:0x0 context:0x0] was sent to an
object that is not KVC-compliant for the "site" property.
Here's the accessor that shows that the target class is indeed KVC
compliant for the "site" property.
- (NSArray *) site
{
return [properties objectForKey: @"site"];
}
Here's the structure of the return from the above method
(
{id=1, name='Boston'},
{id=2, name='New York'},
{id=3, name='Chicago'},
{id=4, name='Los Angeles'},
etc...
)
I've looked at all of mmalc's examples here http://
homepage.mac.com/mmalc/CocoaExamples/controllers.html particularly
the "PopUpTest" project and I just don't see what I'm doing that
is all that different, other than his example is for shared
defaults while mine is for a popup in a dialog
I've been futzing with this for around four hours now trying every
combination of content, content + contentValues, selected values I
can think of, nothing works. What the heck am I doing wrong here?
On May 29, 2006, at 3:01 AM, Ken Tozier wrote:
Hi
I'm having some problems binding the contents of a popup button.
Here's what I've done so far.
1. Create a properties dictionary in my NSWindowController
subclass with the following structure
{
site = {
{id=1, name='Boston'},
{id=2, name='New York'},
{id=3, name='Chicago'},
{id=4, name='Los Angeles'},
etc...
}
}
2. create an accessor method to get the sites from the property
dictionary
- (NSArray *) site
{
return [properties objectForKey: @"site"];
}
3. In the nib file, set the custom class of the file's owner to
MyWindowController.
4. Create an NSArrayController in the nib and connect its
"content" outlet to the file owner
5. Add a "site" key to the array controller.
6. Tried binding the popup to the array controller in each of the
following ways:
- content
Bind to: PopupArrayController
Controller Key: arranged objects
Model key path: <tried leaving empty and entering "site">
-> Result empty popup
- content + contentObjects
Content:
Bind to: PopupArrayController
Controller Key: arranged objects
Model key path: <tried leaving empty and entering "site">
Content Objects:
Bind to: PopupArrayController
Controller Key: selection
Model key path: <tried leaving empty and entering "site">
-> Result empty popup
- contentValues
Bind to: PopupArrayController
Controller Key: site
Model key path: <tried leaving empty and entering "site">
-> Result empty popup
Anyone point out what I'm doing wrong here?
Thanks for any help
Ken
P.S. does anyone know of a good site that explains binding
options in detail? There's so many options for each binding
property, it's really confusing trying to figure out why they
were created in the first place and what situations call for what
options.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40comcast.net
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40comcast.net
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40comcast.net
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden