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

被折叠的 条评论
为什么被折叠?



