Re: Table view active sorting and filter as model changes...
Re: Table view active sorting and filter as model changes...
- Subject: Re: Table view active sorting and filter as model changes...
- From: "Shawn Erickson" <email@hidden>
- Date: Wed, 23 May 2007 17:39:06 -0700
So I subclassed NSArrayController and implement the following. I now
have the behavior I want. Thanks for the pointers!
-Shawn
- (void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object
change:(NSDictionary*)change context:(void *)context
{
[super observeValueForKeyPath:keyPath ofObject:object
change:change context:context];
BOOL requestRearrangeObjects = NO;
if (shouldAutomaticallySort) {
NSArray* sortDescriptors = [self sortDescriptors];
int sortDescriptorCount = [sortDescriptors count];
for (int index = 0; index < sortDescriptorCount; index++) {
NSSortDescriptor* sortDescriptor = [sortDescriptors
objectAtIndex:index];
if ([keyPath isEqualToString:[sortDescriptor key]]) {
requestRearrangeObjects = YES;
break;
}
}
}
if (shouldAutomaticallyFilter) {
// The following does a best attempt at detecting when we need
to refilter...
NSPredicate* filterPredicate = [self filterPredicate];
if (filterPredicate != nil) {
NSRange range = [[filterPredicate predicateFormat]
rangeOfString:keyPath];
if (range.location != NSNotFound) {
requestRearrangeObjects = YES;
}
}
}
if (requestRearrangeObjects) {
if (delay > 0) {
[NSObject cancelPreviousPerformRequestsWithTarget:self
selector:@selector(rearrangeObjects) object:nil];
[self performSelector:@selector(rearrangeObjects)
withObject:nil afterDelay:delay];
} else {
[self rearrangeObjects];
}
}
}
_______________________________________________
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