咱们使用表格控件显示1-1000,因为表格太长,咱们可能会参考电话本的索引功能,在右边显示1,100,200,300,400,...,1000,这样用户点击500,就能快速显示500.函数
也就是设置 动画
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView 函数spa
和orm
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index 函数索引
但咱们点击第一个索引的时候,有时候会出现空白,表格滚动屏幕底部隐藏起来了,触摸一下屏幕,表格又出来了,解决办法就是判断若是是第一个索引,不要使用动画效果it
NSIndexPath *indexPath = nil;io
if (iIndex < 1) { //第一个索引不能用动画效果table
indexPath = [NSIndexPath indexPathForRow:0 inSection:0];scroll
[tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTopanimated:NO];im
}else {
indexPath = [NSIndexPath indexPathForRow:iIndex-1 inSection:0];
[tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTopanimated:YES];
}