Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Index like iOS contact app

I want to create a view like, iOS contact app has,

Basically i want is, Vertical ABCDEFG.... which is located on right side of this image, when user clicks on character M i want to get character M How should i achieve this ? is there any iOS control which gives me this `ABCDEF...?

Thanks in advnace.

EDIT

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    return [[NSArray arrayWithObject:UITableViewIndexSearch] arrayByAddingObjectsFromArray:
            [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles]];
}

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
    if (title == UITableViewIndexSearch)
    {
        CGRect searchBarFrame = self.searchDisplayController.searchBar.frame;
        [tableView scrollRectToVisible:searchBarFrame animated:YES];

        return -1;
    }
    else {
        UILocalizedIndexedCollation *currentCollation = [UILocalizedIndexedCollation currentCollation];
        NSLog(@"selected charecter=%ld",(long)[currentCollation sectionForSectionIndexTitleAtIndex:index]);
        return [currentCollation sectionForSectionIndexTitleAtIndex:index-1];
    }
}
like image 772
Krunal Avatar asked Jul 16 '13 10:07

Krunal


1 Answers

You need to implement these two methods:

// return list of section titles to display in section index view (e.g. "ABCD...Z#")
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView;                                                    
// tell table which section corresponds to section title/index (e.g. "B",1))
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index;

with the corresponding data source:

For example, if you have an array with

`@"Cat", @"Mouse", @"Dog", @"Horse", @"Duck", @"Monkey"`

then you would return and array for sectionIndexTitlesForTableView as :

`@[@"C", @"D", @"H", @"M"]`

because @"Dog" and @"Duck" goes for @"D", @"Mouse" and @"Monkey" goes for @"M" and so on.

And of course, for sectionForSectionIndexTitle, you return the corresponding index for that index. (1 for @"D", 3 for @"M" etc.)

like image 78
Danut Pralea Avatar answered Oct 17 '22 00:10

Danut Pralea