【发布时间】:2016-10-10 13:16:33
【问题描述】:
我正在使用此代码在 tableView 上调用批量更新(开始/结束更新):
let oldImageSet = Set(oldImageArray)
let newImageSet = Set(self.images)
let missingImages = newImageSet.subtracting(oldImageSet)
let missingImageIndexPaths = Array(missingImages).map{NSIndexPath(row: self.images.index(of: $0)!, section: 0)}
//Array(missingImages).map{NSIndexPath(forRow:newImageUUIDArray.indexOf($0)!,inSection:1)}
let removedImages = oldImageSet.subtracting(newImageSet)
let removedImageIndexPaths = Array(removedImages).map{NSIndexPath(row:oldImageArray.index(of: $0)!,section:0)}
self.tableView.beginUpdates()
if missingImageIndexPaths.isEmpty == false {
self.tableView.insertRows(at: missingImageIndexPaths as [IndexPath],with:.top)
}
if removedImageIndexPaths.isEmpty == false {
self.tableView.deleteRows(at: removedImageIndexPaths as [IndexPath],with:.none)
}
self.tableView.endUpdates()
哪个工作正常。
编辑
这是我的 tableView 部分计数以及我如何设置它:
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 55
}
func numberOfSections(in tableView: UITableView) -> Int {
return posts.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
但现在我有另一个 tableView 我希望能够调用它,但它有“Sections”所以当我使用它时我会崩溃......?
有谁知道如何在带有部分的 tableView 上使用此代码?
非常感谢!
【问题讨论】:
-
这与 [objective-c] 有什么关系?
-
@MartinR 好吧,我也会接受 objC 中的答案
-
你能发布崩溃吗?
-
@AkhileshSharma 这里是 i.stack.imgur.com/5NEkO.png
-
只是好奇你为什么要返回部分下的posts.count,这意味着如果有100个帖子,那么1行就会有100个部分
标签: ios swift uitableview