On Nov 13, 2008, at 01:05, Michele Barboni wrote:

Now, in an awakeFromNib: my application connect and query a MySQL database, retrieve entries and store them as MyCustomClass instances, then call addObject: on the NSMutableArray table.. but nothing appears in my NSTableView..

What am I missing?

Adding objects to a NSMutableArray with addObject: is not KVO- compliant. This means that observers of the array (e.g. your NSArrayController) don't get notified of the change automatically.

There are two easy solutions. One is modify the NSMutableArray compliantly. Instead of:

        [table addObject: myCustomObject];

use:

[[appController mutableArrayValueForKey: @"table"] addObject: myCustomObject];

The other is to use NSArrayController's addObject: method, which does approximately the same thing:

        [myArrayController addObject: myCustomObject];

The slight drawback to this approach is that you have to create an IBOutlet on your app controller, and hook it up to the array controller in IB, so that you can have a reference to the NSArrayController to send the addObject: message to.

The other slight complication is that, in general, NSArrayController's arrangedObjects is a sorted and filtered version of the content array. Adding the object via the NSArrayController may put it in a different order from adding it via the NSMutableArray. However, if you have no sorting or filtering, the result should be the same.


_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [EMAIL PROTECTED]

Reply via email to