I have a table view that has a data source from an array that contains the names of people.
Now, to simplify the search for people, I want to split the table view so that it has the letter AZ on the right side, like the address book application.
But my current array just contains a collection NSStrings. How to break them so that they are grouped by the first letter of names? Is there any convenient way to do this?
EDIT: If anyone is interested in my final code:
NSMutableArray *arrayChars = [[NSMutableArray alloc] init];
for (char i = 'A'; i <= 'Z' ; i++) {
NSMutableDictionary *characterDict = [[NSMutableDictionary alloc]init];
NSMutableArray *tempArray = [[NSMutableArray alloc] init];
for (int k = 0; k < [myList count]; k++) {
NSString *currentName = [[friends objectAtIndex:k] objectForKey:@"name"];
char heading = [currentName characterAtIndex:0];
heading = toupper(heading);
if (heading == i) {
[tempArray addObject:[friends objectAtIndex:k]];
}
}
[characterDict setObject:tempArray forKey:@"rowValues"];
[characterDict setObject:[NSString stringWithFormat:@"%c",i] forKey:@"headerTitle"];
[arrayChars addObject:characterDict];
[characterDict release];
[tempArray release];
}
At the end of the function I will have:
arrayChars [0] = dictionary(headerTitle = 'A', rowValues = {"adam", "alice", etc})
arrayChars[1] = dictionary(headerTitle = 'B', rowValues = {"Bob", etc})
Thank you all for your help!
source
share