Table view active sorting and filter as model changes...
Table view active sorting and filter as model changes...
- Subject: Table view active sorting and filter as model changes...
- From: "Shawn Erickson" <email@hidden>
- Date: Tue, 22 May 2007 19:10:21 -0700
So I am now starting to utilize bindings (controller layer) for a new
project that finally allows me the freedom to do so *happy dance* and
I hit an issue that I haven't been able to figure out *sad face*...
---- Short version ----
How do you get an table view that is bound to array controller that is
connected with a model that is modified in a KVO compliant fashion to
automatically resort itself or refilter itself as the model changes?
I have looked at various examples and so far all have non-resort /
non-refilter behavior when the model changes (table cells update as
expected but rows don't get moved up / down as expect to honor the
current sort descriptor for example).
---- Some background ----
I have a data model that is comprised of two main classes that I will
call "ParticipantDB" and "Participant" in this email. ParticipantDB is
notified by a C++ back-end when a participant arrives, leaves, or is
modified (say its email address changes). In the case of participants
arriving the ParticipantDB object creates participant objects and adds
them to a NSMutableSet using a union set mutation wrapped by
appropriate will/did KVO observer notifications. If participants leave
a similar minus set mutation talks place.
For example in the case of an arrive (participantSet is a NSMutableSet)...
[self willChangeValueForKey:@"participants"
withSetMutation:NSKeyValueUnionSetMutation
usingObjects:onlinedParticipants];
[participantSet unionSet:onlinedParticipants];
[self didChangeValueForKey:@"participants"
withSetMutation:NSKeyValueUnionSetMutation
usingObjects:onlinedParticipants];
Related KVC compliant accessor...
- (NSSet*) participants
{
return [[participantSet retain] autorelease];
}
If a property of a participant is modified the ParticipantDB object
gets notified by the C++ back-end and in response the ParticipantDB
object looks up the affected participant object (same object that
exists in the above "participants" set) and uses the appropriate
setter to inform the participant object of the change. For example
[participant setEmail:email]. This again is KVO compliant
modification.
Note all model modifications occur in the context of the main thread
so all KVO notification occur only in the context of the main thread.
I have a table view (in a window) that displays a table of
participants, basically the set of participants that exist in the
above mutable set maintained by ParticipantsDB. This table view has
"content", "selectionIndexes", and "sortDescriptors" bindings all
bound to the same NSArrayController instance. Also the various table
columns have their "value" bindings bound to the NSArrayController
arrangedObjects key with appropriate model key path. The
NSArrayController has "contentSet" binding bound to an
NSObjectController instance. The NSObjectController has
"contentObject" binding bound to a the "participantDB" property of
file's owner. All view and controller objects are of course
instantiated in the same nib.
---- Now to the issue ----
This set up works great with the table view showing the expected
participants and as participants properties get modified the table
view cells update as expected. Additionally I have sort key and sort
selector configured for the table columns and when I click in the
header things sort as expected.
The problem I have is when a sort descriptor is in place (user clicks
in a column to sort the table) and a participant is modified the table
cells update as expected but the table doesn't resort itself.
Similarly if a filter is in place (filter predicate setup via a
standard search field) and the model changes the filter isn't applied
to this updated data.
I hope I am missing something obvious... I would like to have the
table view automatically resort and/or refilter itself as my model
changes... since most of my model changes come in from a remote system
during my applications life cycle.
Thanks,
-Shawn
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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