iphone - Index like iOS 联系人应用

标签 iphone ios ipad contacts

我想创建一个 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/

相关文章:

html - 尽管将其设置为 scale=1,但 Bootstrap 模型未在 iPhone 5s 的全视口(viewport)中显示

iphone - MBProgressHUD 崩溃 "The view used in the MBProgressHUD initializer is nil"

objective-c - ios:防止 ScrollView 缩放超出范围

ios - 无法使用自定义 DelegateProxy 和协议(protocol)接收事件

ios - 如何暂停 iPad 上的所有声音通知?

ios - xcode: 错误 ITMS-90022: "Missing required icon file.."

ios - UIButton 子类中的 imageview.transform 奇怪行为

iphone - NSStream 在关闭时挂起

ios - 滚动父 View 的 CollectionView 以在模式关闭之前显示单元格

iphone - 在自动调整 View 大小后,如何获取 CGRect 值 x、y、宽度、高度?