I have a question friends.Please help me guys.
I am implementing an ios app which is similar to address book.I am able to display the cells with name and email.I am copying my code below. Anyway my question is I have my names in contactValue.name & emails in contactValue.email. Now I need to aplhabetize them in to sections. How can I section them.I mean I just want all the names starting with A into one section and so on.
id alphabet = [arrayOfCharacters objectAtIndex:[indexPath section]];
//---get all names beginning with the letter---
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", alphabet];
// How can I filter the names here using the above predicate condition.I have my names in contactValue.name. According to the names the emails should also placed in the cells.
Contact* contactValue= (Contact*)[contactArray objectAtIndex:indexPath.row];
cell.textLabel.text=contactValue.name;
cell.detailTextLabel.text=contactValue.email;
@sbooth: so u mean the following? But when I do the following , it says Incomapatible pointer types assigning to NsMutableArray from NsArray at the filtering line of code. What does it mean?
id alphabet = [arrayOfCharacters objectAtIndex:[indexPath section]];
//---get all states beginning with the letter---
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", alphabet];
//here names n contactArray are NsMutableArrays.
names = [contactArray filteredArrayUsingPredicate:predicate];
if ([names count]>0) {
Contact* contactValue= (Contact*)[names objectAtIndex:indexPath.row];
cell.textLabel.text=contactValue.name;
cell.detailTextLabel.text=contactValue.email;
Are all your contacts stored in
contactArray? If so, did you try[contactArray filteredArrayUsingPredicate:predicate]?