假设我有一个 PFObject[] 的 firstArray(来自 Parse SDK),它有 7 个项目,我从 firstArray 中创建了一个 secondArray:
secondArray = firstArray
然后我向数据库调用查询以检索更新的数据,它们现在在 firstArray 中有 10 个项目。
我做这样的事情:
if firstArray.count > secondArray.count {
let lastItems = firstArray.count - secondArray.count
// lastItems = 3
}
我如何将最后 3 项按其特定顺序附加到 secondArray 的末尾?
secondArray append item 8
secondArray append item 9
secondArray append item 10
我不想 reloadData(),我只想像 WhatsApp 那样将最后 3 行添加到我的 TableView,否则 TableView 将滚动到顶部。
谢谢!
最佳答案
首先向第二个数组追加数据
secondArray.append(firstArray[index])
然后
self.yourTableView.beginUpdates()
var insertedIndexPaths = [indexpath_where_you_want_insertData]
self.yourTableView.insertRowsAtIndexPaths(insertedIndexPaths, withRowAnimation: .Fade)
self.yourTableView.endUpdates()
关于ios - 如何比较 2 个数组并将最后一项附加到第二个数组 iOS Swift 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42502092/