UITableView要实现右边的索引选择,必须实现以下代理方法
#pragma mark - 返回索引字母数组
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
NSArray *sectionArray = [NSArray arrayWithObjects:@"X", @"Y", @"Z", nil];
//添加搜素图标
[sectionArray insertObject:UITableViewIndexSearch atIndex:0];
return sectionArray;}
#pragma mark - 触摸索引事件
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
//...
if(title == [self.sectionTitleArray objectAtIndex:index])
{
[self tableViewSectionIndexTouched:title];
}
return index;
}
- (void) tableViewSectionIndexTouched:(NSString *)title
{
//加载一个UIView,显示选中后的字母,如imageViewIndex;
dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC);
dispatch_after(time, dispatch_get_main_queue(), ^{
self.imageViewIndex.hidden = YES;
});
}