Cocoa Touch UITableView Alphabetical '#' Match All Unmatched
- by Kevin Sylvestre
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.