On May 27, 2010, at 2:43 PM, Bill Appleton wrote:

> *5)** **I **can't create a simple list*
> 
> I did it the only way I could -- with a table that has one column, etc. Man
> that was painful for a simple list. Is there a better way?

Have a look at NSArrayController. It makes table views a piece of cake. You set 
one up basically like this:

1. You create an object with an NSArray property, and write the getters and 
setters (or synthesize them).

2. In IB, you drag an NSObjectController into the nib and set its ‘content’ 
outlet to the object in step 1.

3. You now drag an NSArrayController into the nib, and in the Bindings pane of 
its Get Info window, enable its Content Array binding, bind it to your object 
controller, and set the Model Key Path to the name of the property in step 1 
(leave Controller Key at the default, ‘selection’).

4. In the Attributes pane of the NSArrayController’s Get Info window, set Class 
Name to the name of the class of the objects that populate the array.

4. Now, the final step: you select the table column in your NSTableView 
(double-clicking a column body will select the column), bind it to your array 
controller, and set the Value binding to the following: Controller Key is 
arrangedObjects (the default), Model Key Path is the name of a property (or a 
dictionary key, if your objects are NSDictionaries) that will get a nice 
NSString or other displayable object to show in the table column.

And you’re done. Zero code, and your table view is ready to go.

Charles_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to