UITableView刷新而不滚动

编程入门 行业动态 更新时间:2024-10-27 17:10:19
本文介绍了UITableView刷新而不滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个带有项目的_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刷新而不滚动

本文发布于:2023-11-26 19:53:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634964.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:而不   UITableView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!