[英]Add cells to top of UITableView
I want to add rows to a table view without the visible cells being moved, similarly to Twitter for iPhone, Tweetbot and several others. 我想在不移动可见单元格的情况下向表格视图添加行,这与iPhone,Tweetbot和其他几个推特类似。 Every method I have tried thus far accomplishes that eventually, but does funky animations in between.
到目前为止,我尝试过的每种方法最终都可以实现这一目标,但是在两者之间却要进行时髦的动画处理。 Here is the current solution, which moves cells around but eventually ends up staying in the same place.
这是当前的解决方案,该解决方案可移动单元格,但最终最终停留在同一位置。
- (void)controllerDidChangeContent:(NSFetchedResultsController*)controller
{
UITableViewCell *referenceCell;
if ([self.tableView.visibleCells count] > 0) {
referenceCell = [self.tableView.visibleCells lastObject];
}
CGFloat offset = referenceCell.frame.origin.y - self.tableView.contentOffset.y;
[self.tableView endUpdates];
[self.tableView setContentOffset:CGPointMake(0.0, referenceCell.frame.origin.y - offset) animated:NO];
}
Try this: 尝试这个:
-insertRowsAtIndexPaths:withRowAnimation:
on the UITableView
with UITableViewRowAnimationNone
. UITableViewRowAnimationNone
在UITableView
上调用-insertRowsAtIndexPaths:withRowAnimation:
You can specify all index paths that you want to insert in one go. -setContentOffset:
just as before -setContentOffset:
和以前一样 Avoid calling -beginUpdates
and -endUpdates
on the table view. 避免在表视图上调用
-beginUpdates
和-endUpdates
。 -endUpdates
causes animations to be done for the original cells. -endUpdates
导致对原始单元进行动画处理。
It seems that insertRowsAtIndexPaths alone may animate cells. 似乎单独的insertRowsAtIndexPaths可以使单元动画。 You could try a workaround like this:
您可以尝试这样的解决方法:
for (UITableViewCell *cell in [tableView visibleCells])
{
[cell.layer removeAllAnimations];
}
Could you just reload the data source, and immediately call 您能否重新加载数据源,然后立即调用
[tableview selectRowAtIndexPath: animated:NO scrollPosition:<#(UITableViewScrollPosition)#>];
You would probably need to get the current position which you could do with 您可能需要获取可以处理的当前职位
[[tableview indexPathsForVisibleRows] objectAtIndex:0];
I haven't tested this out though, so I'm not 100% on it. 我还没有测试过,所以我不是100%。
Just posted an answer with code snippets here 刚刚在此处发布了带有代码段的答案
Keep uitableview static when inserting rows at the top 在顶部插入行时使uitableview保持静态
Basically: 基本上:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.