我想创建一个 View ,例如 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"
等)
关于iphone - Index like iOS 联系人应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17674077/