insertRowsAtIndexPaths使用自定义单元格UITableView和UITableViewAutomaticDimension跳转

时间:2015-09-27 11:28:05

标签: swift uitableview

当用户向下滚动时,我正在向我的UITableView动态添加单元格。它工作得很好。

我遇到的问题是在添加新行后,tableview会跳转。我需要它保持原位并将新行添加到底部,我认为默认情况下会这样做。我不确定我在这里做错了什么,或者在使用UITableViewAutomaticDimension时这是一个错误。

在渲染新单元格之前有一个白色闪烁。

我的代码是

 func offerNotification(hasError : Bool?, errorDescription : String?, isCategory : String?, isComplete : Bool, isPagination : Bool, offerUpdate : NSMutableArray?){
    //Append New & Old Array
    let count = self.offersArray.count - 1
    self.offersArray.addObjectsFromArray(offerUpdate! as [AnyObject])

    //Create Array of Indexpaths
    var indexpaths : Array<NSIndexPath> = []
     for (index, _) in offerUpdate!.enumerate() {
        let nspath = NSIndexPath(forRow: count + index, inSection: 0)
        indexpaths.append(nspath)
    }

    //Add to Table
    self.tableView.insertRowsAtIndexPaths(indexpaths, withRowAnimation: UITableViewRowAnimation.Automatic)
    self.tableView.endUpdates()

}

有人经历过这个吗?

此处显示此问题的测试项目https://github.com/oddpanda/Endless-Scrolling-Test

1 个答案:

答案 0 :(得分:0)

对于遇到同样问题的人。

我的委托方法中有estimatedHeightForRowAtIndexPath,删除后 解决了我的所有问题。

可能是我的问题所独有,但希望它可以帮助某人。

相关问题