Re: Tracking changes to NSTableView datasource
Re: Tracking changes to NSTableView datasource
- Subject: Re: Tracking changes to NSTableView datasource
- From: Graham Cox <email@hidden>
- Date: Sat, 1 Nov 2008 10:11:19 +1100
On 1 Nov 2008, at 9:37 am, Andre Masse wrote:
I have a datasource for an NSTableView which is a NSMutableArray
(call it mainArray for the moment) and I'm not sure which way is
better to manage add, update and delete rows. I can use either one
array for each of those cases or add a field to the mainArray (like
1 for new, 2 for update) and only one array for the records to
delete (I'm using a back-end database). The first problem with the
former is if (when) the user add a row and modify it later on (but
before any updates to the back-end are done) I will need to check if
its a new row (by quering the newRows array) and then not add it to
the update array if it is. Not counting keeping both array content
in sync... With the later, only checking the field will tell me if
its a new row or not. At this point, I prefer the second method and
can't see too many problems with it... Now, how you guys handle
these kind of things?
To be honest I can hardly follow this at all.
You say:
I have a datasource for an NSTableView which is a NSMutableArray
This can't be, since NSMutableArray doesn't implement the
NSTableDataSource protocol. So what I'm assuming you've actually got
is a controller in between the two. That being the case, your
controller should do the work. When the user adds a row, the
controller adds the row to the data model and updates the table. If
the data is updated, the controller notices the change (using some
means, notifications or KVO for example) and updates the table.. and
so on. It's standard MVC and highly applicable in most cases of a
table hooked to an array. You could use NSArrayController to give you
much of this for free.
Your situation *may* be more complicated - you certainly made it sound
complicated - but is it?
n.b. if you're concerned about discovering what changed between one
array and another, a possible easy way to do this is to create a NSSet
from each one and subtract them.
Now, how you guys handle these kind of things?
As stated ;-)
hth, Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden