I am working on a contact list for my iphone applications. I have made a custom object class that contains the following attributes.
- Firstname
- Lastname
- Id
Now I want to make a contact list like the iphone’s contact list. So with A-B-C-D-E-… as the tableview section headers. I was following this tutorial.
But he is just working with strings. My problem is lying inside the CellForRow. Here you can see what I have ATM.
NSString *alphabet = [firstIndex objectAtIndex:[indexPath section]];
//---get all states beginning with the letter---
NSPredicate *predicate =
[NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", alphabet];
NSLog(@"list content is here %@",[listContent valueForKey:@"name"]);
NSArray *contacts = [[listContent valueForKey:@"name"] filteredArrayUsingPredicate:predicate];
NSLog(@"Contacts array is %@",contacts);
Contact *contact = nil;
contact = [contacts objectAtIndex:[indexPath row]];
NSLog(@"contact is in de else %@",contact.name);
NSString *text = [NSString stringWithFormat:@"%@ %@",contact.name,contact.firstName];
cell.textLabel.text = text;
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
I crashes on the first row with the following Log
2013-02-07 10:52:47.963 Offitel2[7807:907] list content is here (
Claes,
Geelen,
Verheyen
)
2013-02-07 10:52:47.964 Offitel2[7807:907] Contacts array is (
Claes
)
2013-02-07 10:52:47.964 Offitel2[7807:907] -[__NSCFString name]: unrecognized selector sent to instance 0x208e2c20
2013-02-07 10:52:47.965 Offitel2[7807:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString name]: unrecognized selector sent to instance 0x208e2c20'
Can anybody help me with this?
Kind regards
Follow these steps:
Now sort it:
Now implement
Final suggestion, take a dictionary of all names and group name with firstletter as key in dictionary, Eg.:
In this way
indexAlphabetArray = [nameDictionary allKeys];Edit: Lets make it more easy for you: