views:

753

answers:

1

Hi, I want to implement an index that is being displayed at the right side of a table. I've found out how to display it. How can I scroll to a certain position in my table, after a certain index item was pressed?

In the index I am not displaying all the alphabet, but in the following manner:

#define ALPHA_ARRAY= @"A●D●G●J●M●P●S●V●Z"

So when the user presses between A and D I want to go to items starting from A and so on. .

How can I implement it?

I want to make something similar to the index available in the contacts application on iPhone.

+2  A: 

You need to implement this method in your table view data source:

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

The table view gives you the index of the section the user touched, along with its title (in this case, one of the letters you specified). You need to return the index of the section. If there are exactly as many sections as there are indexes, all you have to do is return index. Otherwise, you'll need to figure out the index of the section the table view should scroll to and return that instead.

Alex