lav*_*voy 15 iphone objective-c uitableview
我有一个从Web服务中提取的数据列表.我刷新数据,我想在当前数据上方的表视图中插入数据,但我想在tableview中保持当前的滚动位置.
现在我通过在当前部分上方插入一个部分来完成此操作,但它实际上是插入,向上滚动,然后我必须手动向下滚动.我尝试在此之前禁用滚动表,但这也不起作用.
这看起来很不稳定,看起来很黑.有什么更好的方法呢?
[tableView beginUpdates];
[tableView insertSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
[tableView endUpdates];
NSUInteger iContentOffset = 200; //height of inserted rows
[tableView setContentOffset:CGPointMake(0, iContentOffset)];
Run Code Online (Sandbox Code Playgroud)
use*_*951 17
如果我理解你的使命,
我是这样做的:
if(self.tableView.contentOffset.y > ONE_OR_X_ROWS_HEIGHT_YOUDECIDE
{
self.delayOffset = self.tableView.contentOffset;
self.delayOffset = CGPointMake(self.delayOffset.x, self.delayOffset.y+ insertedRowCount * ONE_ROW_HEIGHT);
[self.tableView reloadData];
[self.tableView setContentOffset:self.delayOffset animated:NO];
}else
{
[self.tableView insertRowsAtIndexPath:indexPathArray WithRowAnimation:UITableViewRowAnimationTop];
}
Run Code Online (Sandbox Code Playgroud)
使用此代码,如果用户位于表的中间而不是顶部,则uitableview将重新加载新行而不进行动画而不进行滚动.如果用户位于表格的顶部,他将看到行插入动画.
请注意代码,我假设行的高度相等,如果没有,只需计算要插入的所有新行的高度.希望有所帮助.
我发现获得所需行为的最佳方法是根本不动画插入动画.动画导致了波动.
相反,我打电话给:
[tableView reloadData];
// set the content offset to the height of inserted rows
// (2 rows * 44 points = 88 in this example)
[tableView setContentOffset:CGPointMake(0, 88)];
Run Code Online (Sandbox Code Playgroud)
这使得重新加载在内容偏移改变的同时出现.
| 归档时间: |
|
| 查看次数: |
19585 次 |
| 最近记录: |