您的位置:首页 > 产品设计 > UI/UE

UITableView 右边索引第一个出现空白情况的解决办法

2013-05-05 02:45 375 查看
我们使用表格控件显示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];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐