[Q] Any constant meaning empty string in the NSSearchField?
[Q] Any constant meaning empty string in the NSSearchField?
- Subject: [Q] Any constant meaning empty string in the NSSearchField?
- From: JongAm Park <email@hidden>
- Date: Tue, 23 Jan 2007 19:25:48 -0800
From: email@hidden
Subject: [Q] Any constant meaning empty string in the NSSearchField?
Date: January 23, 2007 7:20:20 PM PST
To: email@hidden
Hello.
To study how to use the Cocoa Binding for filtering data from a
NSTableView,
I read the "Cocoa Bindings Programming Topics" available from the Apple.
Although I added a NSSearchField and made it work, I found a weird
issue.
When a text typed into a NSSearchField is deleted and press return
key to see unfiltered data
from a NSTableView, it throws some strange value, 0xa07c1254.
Here is the code.
- (IBAction)search:(id)sender // Action connected to the NSSearchField
{
[self setSearchString:[sender stringValue]];
[self rearrangeObjects];
}
- (void)setSearchString:(NSString *)aString
{
[aString retain];
[searchString release];
if( aString == (NSString *)0xa07c1254 ) // This value is interesting !!
searchString = nil;
else
searchString = aString;
}
- (NSArray *)arrangeObjects:(NSArray *)objects
{
if( searchString == nil )
return [super arrangeObjects:objects];
NSMutableArray *filteredObjects = [NSMutableArray arrayWithCapacity:
[objects count]];
NSEnumerator *objectsEnumerator = [objects objectEnumerator];
NSString *titleValue;
id item;
while( item = [objectsEnumerator nextObject] ) {
titleValue = [item valueForKeyPath:@"title"];
if( [titleValue rangeOfString:searchString
options:NSAnchoredSearch].location != NSNotFound) {
[filteredObjects addObject:item];
}
}
return [super arrangeObjects:filteredObjects];
}
On the NSSearchField and its cell reference, the value, 0xa07c1254,
is not explained.
I checked if it is a kind of address pointing to address space I
don't know.
However, whenever I launch the sample app, and try pressing return key
after removing text in the field it throws the same value.
So, I guess it is not an address.
Probably it is a constant value meaning that there is no text in the
NSSearchField.
Can anyone explain me about this?
Thank you in advance.
JongAm Park
_______________________________________________
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