• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Table view active sorting and filter as model changes...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Table view active sorting and filter as model changes...
      • From: "Shawn Erickson" <email@hidden>
References: 
 >Table view active sorting and filter as model changes... (From: "Shawn Erickson" <email@hidden>)
 >Re: Table view active sorting and filter as model changes... (From: "Shawn Erickson" <email@hidden>)
 >Re: Table view active sorting and filter as model changes... (From: "Shawn Erickson" <email@hidden>)
 >Re: Table view active sorting and filter as model changes... (From: mmalc Crawford <email@hidden>)
 >Re: Table view active sorting and filter as model changes... (From: "Shawn Erickson" <email@hidden>)

  • Prev by Date: Re: Predefining number of copies for the print panel.
  • Next by Date: CoreData stores and networked home directories
  • Previous by thread: Re: Table view active sorting and filter as model changes...
  • Next by thread: Re: Table view active sorting and filter as model changes...
  • Index(es):
    • Date
    • Thread