【发布时间】:2014-11-18 14:47:38
【问题描述】:
我有一个 tableView。当用户点击其中一条记录时,我检查它的属性并基于此过滤结果并仅显示相似的结果 - 所以我需要刷新 tableView。
问题是用户可以向上/向下滚动 tableView。我需要滚动 tableView,使单元格与刷新前的UITableViewScrollPosition 完全相同。
显然,我正在保存最后点击的项目
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
_lastSelectedItem = [self itemForIndexPath:indexPath];
}
然后重新加载tableView后:
NSIndexPath *indexPath = [self indexPathForItem:_lastSelectedItem];
if (_tableView.numberOfSections > indexPath.section && [_tableView numberOfRowsInSection:indexPath.section] > indexPath.row) {
[_tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:NO];
_lastSelectedItem = nil;
}
这很好但是...用户无法在UITableViewScrollPositionMiddle 完成。他本可以在UITableViewScrollPositionTop 或UITableViewScrollPositionBottom 或什至介于两者之间完成滚动。
-- 编辑--
通过偏移量计算也是有问题的,因为偏移量是视图开始位置和顶部表格滚动位置之间的差异。而我对这个值不感兴趣:/。
【问题讨论】:
标签: ios objective-c uitableview uiscrollview uiscrollviewdelegate