我想创建一个像iOS联系人应用的视图,
Basically i want is,Vertical
ABCDEFG....
which is located on right
side of this image,when user clicks on characterM
i want to
get characterM
How should i achieve this ? is there any iOS
control which gives me this `ABCDEF…?
谢谢你的支持.
编辑
- (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]; } }
解决方法
您需要实现这两种方法:
// 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;
与相应的数据源:
例如,如果您有一个数组
`@"Cat",@"Mouse",@"Dog",@"Horse",@"Duck",@"Monkey"`
然后你将返回和sectionIndexTitlesForTableView数组:
`@[@"C",@"D",@"H",@"M"]`
因为@“Dog”和@“Duck”代表@“D”,@“Mouse”和@“Monkey”代表@“M”,依此类推.
当然,对于sectionForSectionIndexTitle,您将返回该索引的相应索引. (1表示@“D”,3表示@“M”等)