Re: Filtering tableview problems
Re: Filtering tableview problems
- Subject: Re: Filtering tableview problems
- From: Scott Anguish <email@hidden>
- Date: Tue, 24 Feb 2004 02:35:32 -0500
also, just to follow up, another bug is that if searchField is nil you
need to call super
finally, you need to retain that string below..
the updated source is below
The FilteringArrayController implementation file
#import "FilteringArrayController.h"
#import <Foundation/NSKeyValueObserving.h>
@implementation FilteringArrayController
- (void)search:(id)sender {
[self setSearchString:[sender stringValue]];
[self rearrangeObjects];
}
- (NSArray *)arrangeObjects:(NSArray *)objects {
if (searchString == nil) {
return [super arrangeObjects:objects];
}
NSMutableArray *filteredObjects = [NSMutableArray
arrayWithCapacity:[objects count]];
NSEnumerator *objectsEnumerator = [objects objectEnumerator];
id item;
while (item = [objectsEnumerator nextObject]) {
if ([[item valueForKeyPath:@"title"] rangeOfString:searchString
options:NSAnchoredSearch].location != NSNotFound) {
[filteredObjects addObject:item];
}
}
return [super arrangeObjects:filteredObjects];
}
- (void)setSearchString:(NSString *)aString
{
[aString retain];
[searchString release];
searchString=aString;
}
@end
On Feb 23, 2004, at 6:21 PM, Scott Anguish wrote:
On Feb 23, 2004, at 1:37 PM, Francisco Tolmasky wrote:
This question has already been posted once, but with no avail. I'm
having trouble filtering an nstableview with bindings. What happens
is that the search field loses focus when the table view rearranges
itself. Does anyone know a solution to this?
Yes. The docs have a task that covers this, but it has a bug. The
solution is to remove the binding that has been created to the
content, and add a line to the search: method before it rearranges the
objects to get the stringValue from the sender..
searchString=[sender stringValue];
This is corrected in the next release of the docs.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.