Deepak Thakur
Deepak Thakur

Reputation: 3691

Implement 'search' OR sort in ios

I get list of names from web service in table view. My requirement is that I need to display the names starting from alphabet A / B / C and so on in iOS. Please refer image (red rectangle) below. Any suggestions how to implement this?

enter image description here

Upvotes: 0

Views: 76

Answers (2)

Simon
Simon

Reputation: 25993

Your friend here is UILocalizedIndexedCollation. There's an explanation of how to use it at NSHipster.

Upvotes: 0

Fr4ncis
Fr4ncis

Reputation: 1387

Take a look at the UITableViewDataSource methods

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index

you need to return an array with the titles for the various sections that will appear on the right. For instance:

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    return @[@"A",@"B",@"C"];
}

and

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
    return index;
}

return the index of the section to scroll to once the index on the right is tapped. You have to handle with sorting yourself, all the indexes do is scrolling to a certain section when an index on the right is tapped.

Upvotes: 2

Related Questions