• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Cocoa Bindings and popups
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cocoa Bindings and popups


  • Subject: Re: Cocoa Bindings and popups
  • From: Steve Harris <email@hidden>
  • Date: Mon, 19 Jul 2004 04:22:47 +0100

I'm having trouble using Cocoa Bindings to present an array in a popup button. My main Controller object contains an NSMutableArray called "rideDescriptionList", which contains a bunch of custom "RideDescription" objects. These have two NSStrings ("label" and "description") and an NSNumber ("distance") as instance variables.

I want the popup to show the contents of each object's "label" and, when new RideDescriptions are added to the array, have them added to the popup. Here's what I did in Interface Builder:

1.) Created an NSObjectController object called "PostAlias" and set its "content" outlet to point to my Controller object (which is named "PostController").

Set the Object Class Name to NSMutableArray in the "Attributes" inspector.

2.) Created an NSArrayController called "RideList" and in the "Bindings" inspector, set the contentArray binding to this:

Bind to: PostAlias
Controller Key: selection
Model Key Path: rideDescriptionList

Set the Object Class Name to RideDescription in the "Attributes" inspector.

3.) Set the NSPopupButton's bindings to these settings:

content:
Bind to: RideList
Controller Key: arrangedObjects
Model Key Path: <none>

contentValues:
Bind to: RideList
Controller Key: arrangedObjects
Model Key Path: label

I've confirmed that new RideDescription objects are being created, but they never show up in the popup button. I've missed something, either conceptually or in the mechanics of making the connections. Does the above look right? How do I find the missed "connection"? I did pattern my bindings on the example project at CocoaDevCentral, but obviously I didn't do it perfectly. I guess what I'm looking for is hints on how to debug.

Thanks,

Chuck
It could be that you need to make your accessor methods for rideDescriptionList Key-Value Coding compliant.

http://developer.apple.com/documentation/Cocoa/Conceptual/ KeyValueCoding/Concepts/Compliant.html

This would mean that in your content objects for PostAlias you have methods like this:

- (unsigned)countOfRideDescriptionList
{
return [rideDescriptionList count];
}

- (id)objectInRideDescriptionListAtIndex:(unsigned)index
{
return [rideDescriptionList objectAtIndex:index];
}

and likewise - (void)insertObject:(id)theObject inRideDescriptionListAtIndex:(unsigned)index and (void)removeObjectFromRideDescriptionListAtIndex:(unsigned)index

Although it says you can just return a mutable array, I've found if you have other controllers observing the array they work by observing these methods.

Hope that helps,

Steve
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: Cocoa Bindings and popups
      • From: Scott Anguish <email@hidden>
    • Re: Cocoa Bindings and popups
      • From: Chuck Musser <email@hidden>
  • Prev by Date: Re: cocoa app from scratch
  • Next by Date: Re: cocoa app from scratch
  • Previous by thread: Cocoa Bindings and popups
  • Next by thread: Re: Cocoa Bindings and popups
  • Index(es):
    • Date
    • Thread