gpt4 book ai didi

IOS:如何将 NSArray 转换为 NSIndexPath

转载 作者:太空宇宙 更新时间:2023-11-03 17:34:41 24 4
gpt4 key购买 nike

我想批量插入 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

关于IOS:如何将 NSArray 转换为 NSIndexPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20799840/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com