On Oct 18, 2010, at 23:02, Chris Share wrote:

> I'm using an NSMutable array as my data source for the table. The problem I'm 
> having is in clearing the array for each new folder.

You have a conceptual problem here. "Data source" means something specific in 
Cocoa -- an object that implements the NSTableViewDataSource protocol. If 
you're using a data source, then the object *isn't* an array (though of course 
a data source may use an array for its backing store, but that doesn't look 
like what you're doing here).

The only other way to provide data to a table is via a binding. In that case, 
the data comes from an array *property* of some object (which itself may be 
using an array as its backing store).

If you're using a data source (properly named), then your error isn't in the 
code you posted, but in one of the NSTableViewDataSource methods.

If you're using a binding, then your error is (at least) that you're not 
updating your array property KVO compliantly. In your openButtonClick method, 
instead of making changes directly to your inputArray backing storage, you 
should use the KVO-compliant mutable proxy:

        NSMutableArray* mutableInputFiles = [self mutableArrayValueForKey: 
@"inputArray"];
        [mutableInputFiles removeAllObjects];
        ...
        [mutableInputFiles addObject: fileName];

and then you shouldn't need to call 'reloadData' at all.

However, you may still run into some problems, because you've been thinking in 
terms of data coming from an array variable, instead of from an array property 
(which is what KVC and KVO is all about). The above code only works because 
Cocoa is able to pretend that a property exists where there is only an instance 
variable, but that's more of a historical anomaly than a desirable feature. You 
would be well advised to define the property explicitly using @property, and 
make sure that all code that refers to the data is property-aware rather than 
ivar-aware.


_______________________________________________

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