Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableView:如何';固定和#x27;行插入后的当前单元格?_Ios_Uitableview - Fatal编程技术网

Ios UITableView:如何';固定和#x27;行插入后的当前单元格?

Ios UITableView:如何';固定和#x27;行插入后的当前单元格?,ios,uitableview,Ios,Uitableview,我的视野很开阔。我想在表的顶部插入一些行。但是在插入之后,旧的细胞被向下推 NSArray *indexPaths = @[[NSIndexPath indexPathForRow: 0 inSection: 0]]; [self.tableView insertRowsAtIndexPaths: indexPaths withRowAnimation: UITableViewRowAnimationNone]; 例如: 插入前: 项目1 项目2 项目3 项目4 项目5 插入后 项目-

我的视野很开阔。我想在表的顶部插入一些行。但是在插入之后,旧的细胞被向下推

NSArray *indexPaths = @[[NSIndexPath indexPathForRow: 0 inSection: 0]];
[self.tableView insertRowsAtIndexPaths: indexPaths withRowAnimation: UITableViewRowAnimationNone];
例如: 插入前:

  • 项目1
  • 项目2
  • 项目3
  • 项目4
  • 项目5
插入后

  • 项目-5
  • 项目-4
  • 项目-3
  • 项目1
  • 项目2
我希望将项目1保持在其“旧位置”,例如:

插入后

  • 项目1
  • 项目2
  • 项目3
新插入的单元格位于旧单元格的上方(屏幕上未显示)。

请尝试以下操作:

 [tableView scrollToRowAtIndexPath:value atScrollPosition:UITableViewScrollPositionTop animated:NO];
注意,该值将是indexPath,行数作为添加的新行数

要创建和使用

[NSIndexPath indexPathForRow:inSection:]

我自己解决了这个问题。我觉得它更流畅,有更好的用户体验

    for (Poi *poi in fetchedObjects) {
        [self.objects insertObject: poi atIndex: 0];
    }

    CGFloat totalHeight = 0;
    for (int i=0; i<fetchedObjects.count; ++i) {
        totalHeight += [self tableView: self.tableView heightForRowAtIndexPath: [NSIndexPath indexPathForRow: i inSection: 0]];
    }

    CGPoint currentContentOffset = self.tableView.contentOffset;
    currentContentOffset.y += totalHeight;
    [self.tableView reloadData];
    self.tableView.contentOffset = currentContentOffset;
for(获取对象中的Poi*Poi){
[self.objects insertObject:poi-atIndex:0];
}
CGFloat总高度=0;

对于(int i=0;iSet scroll position in UITableView…[TableView ScrollToRowatineXpath:[nsIndepath indexPathForRow:savedScrollPosition:0]atScrollPosition:UITableView ScrollPosition Top动画:否];它可以解决问题,但不是最好的解决方案。屏幕会闪烁几次,这不是很好的用户体验。添加所有行,然后滚动到第一行?这样可以确保屏幕只闪烁一次。所以我想这应该不是问题。