Cocoa Touch UITableView Alphabetical '#' Match All Unmatched
Posted
by Kevin Sylvestre
on Stack Overflow
See other posts from Stack Overflow
or by Kevin Sylvestre
Published on 2010-04-22T15:50:14Z
Indexed on
2010/04/22
15:53 UTC
Read the original article
Hit count: 492
I have a UITableView containing names that I would like to group (and sort) by the first letter (similar to the Address Book application). I am currently able to match any section ('A'-'Z') using:
// Sections is an array of strings "{search}" and "A" to "Z" and "#".
NSString *pattern = [self.sections objectAtIndex:section];
NSPredicate *predicate = nil;
// Ignore search pattern.
if ([pattern isEqualToString:@"{search}"]) return nil;
// Non-Alpha and Non-Diacritic-Alpha (?).
if ([pattern isEqualToString:@"#"]);
// Default case (use case and diacritic insensitivity).
if (!predicate) predicate = [NSPredicate predicateWithFormat:@"name beginswith[cd] %@", pattern];
// Return filtered results.
return [self.friends filteredArrayUsingPredicate:predicate];
However, matching for the '#' eludes me. I tried constructing a REGEX match using:
[NSPredicate predicateWithFormat:@"name matches '[^a-zA-Z].*'"];
But this fails for diacritic-alpha (duplicate rows appear). Any ideas would be greatly appreciated! Thanks.
© Stack Overflow or respective owner