开发者

How do you create an indexed table view based on last name

If you could fi开发者_Go百科nd a tutorial for an indexed table view based on last name like the "Contacts" app, that would be great. I've search all around but can't find one on last names.


I guess you store your contacts using core data. You probably have a entity "Person" with attributes first name, last name, address etc.

You should make a subclass of NSManagedObject specifically for the entity "Person". In this class, you add a method that returns only the first letter of the last name. If you have a NSFetchedResultsController you can apply the path name for the sections. There you just write the name of exactly that method that returns the first letter. The table view should then be sectioned by the last name's first letter like in contacts.

Now, you should implement the method

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView

You return a array that contains all the index titles which will appear on the right. Let's say if your contacts are "Steve Jobs" and "Jony Ive", there would be two sections and two index titles "I" and "J". You don't have to put all letters of the whole alphabet in the array, just those that you really need.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜