我想批量插入 UITableview。
MyArray.all() do |datas|
self.tableView.beginUpdates
self.tableView.insertRowsAtIndexPaths(datas, withRowAnimation: UITableViewRowAnimationFade)
self.tableView.endUpdates
self.myarrayvar += datas
end
'myarrayvar' 是 MyArray 的数组。我试着引用 apple documentation
和stackoverflow这与我的问题相似。
但我真的不知道如何转换我的数据,以适应 insertRowsAtIndexPaths 函数的参数。
使用 ruby 运动
这是我目前使用的一种方式:
def insertCellsAtBottom(newData)
# Get count for the existing data you have.
currentCount = @data.count
# Build the indexPaths for the new data, adding to the current count each time.
# This will make sure you are creating the correct indexes.
indexPaths = newData.map.with_index do |obj, index|
NSIndexPath.indexPathForRow(currentCount + index, inSection: 0)
end
# Update your datasource and insert the rows.
self.tableView.beginUpdates
@data.addObjectsFromArray(newData)
self.tableView.insertRowsAtIndexPaths(indexPaths, withRowAnimation: UITableViewRowAnimationFade)
self.tableView.endUpdates
end
我是一名优秀的程序员,十分优秀!