gpt4 book ai didi

iphone - Index like iOS 联系人应用

转载 作者:可可西里 更新时间:2023-11-01 03:39:21 32 4
gpt4 key购买 nike

我想创建一个 View ,例如 iOS 联系人应用,

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...?

提前致谢。

编辑

- (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/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com