• 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: NSController question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSController question


  • Subject: Re: NSController question
  • From: Chris Hanson <email@hidden>
  • Date: Wed, 5 Nov 2003 15:18:11 -0600

On Nov 5, 2003, at 1:38 PM, Jeff LaMarche wrote:
Let's say that I have a "model" class that holds all of the data for a particular piece of functionality. One of the iVars in that model class is an array of objects. Within the same window, I'd like to display some of the non-collection iVars from the "model" class, but also display in a table the data from the array it contains.

Lets say you have a class named Model:

@interface Model : NSObject {
NSString *myString;
NSMutableArray *myArray;
}
@end

Let's say we want to create an interface that shows myString in a text field and myArray in a table view. Here's what I'd do:

(1) Instantiate an NSObjectController to manage an instance of Model. Tell it its keys are "myString" and "myArray" and its object class name is "Model". Its contentObject will need to be set to an instance of Model at some point; one way to do this by binding its contentObject to a key in File's Owner (an instance of MyDocument for the default document-based application nib).

(2) Bind your text field's content value to NSObjectController's "myString" key.

(3) In the same file, instantiate an NSArrayController to manage the array. Bind its contentArray to the key myArray in the NSObjectController from (1). Now you should be able to use this NSArrayController as usual to manage the array/table interaction.

As for "dot notation," you're referring to key paths in key-value coding. Key-Value Coding is the foundation on which all of the Cocoa Bindings functionality is built, so key paths should generally work.

-- Chris

--
Chris Hanson, bDistributed.com, Inc. | Email: email@hidden
Outsourcing Vendor Evaluation | Phone: +1-847-372-3955
Custom Mac OS X Development | Fax: +1-847-589-3738
http://bdistributed.com/ | Personal Email: email@hidden
_______________________________________________
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.

References: 
 >NSController question (From: Jeff LaMarche <email@hidden>)

  • Prev by Date: Re: XCode usable?
  • Next by Date: Fix and Continue broken?
  • Previous by thread: NSController question
  • Next by thread: screensaver and expose
  • Index(es):
    • Date
    • Thread