我有一个带有项目的_TableView,我想设置自动刷新,并且我不希望它在刷新时滚动,可以说用户向下滚动了2页,并且刷新触发了->,所以我想将刷新的内容放在表格的顶部,而不会影响用户的滚动
I have a _TableView with items , and I want to set automatic refresh,and I don't want it to scroll on refresh , lets say user scrolled 2 pages down , and the refresh trigered -> so I want to put the refreshed content to the top of the table without interupting user's scrolling
假设用户位于第18行 现在_dataSource刷新了,所以它取了4个项目,所以我希望用户继续使用他以前的项目.
Assume user was on row 18 and now the _dataSource is refreshed so it fetched lets say 4 items , so I want user to stay on the item he was.
实现它的最佳方法是什么?
What would be the best approach to achieve it ??
推荐答案我正在显示是否仅添加一行.您可以将其扩展为多行.
I am showing if only one row is being added. You can extend it to multiple rows.
// dataArray is your data Source object [dataArray insertObject:name atIndex:0]; CGPoint contentOffset = self.tableView.contentOffset; contentOffset.y += [self tableView:self.tableView heightForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; [self.tableView reloadData]; [self.tableView setContentOffset:contentOffset];但是要执行此操作,您需要定义- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath方法.否则,如果常量不变,您可以直接给您的tableview行高.
But for this to work you need to have defined - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath the method. Or else, you can directly give your tableview row height if it is constant.
更多推荐
UITableView刷新而不滚动
发布评论