0
夫特3夫特:断言故障时按钮点击
我有几个行的表图,每一行有一个按钮(使用indexPath.row)时,按钮被点击时,它从第1部分移动所述行( testArray)至部分0(,其次是数组)。但是当使用搜索栏搜索testArray并单击某行的按钮时,它会崩溃。
现在,使用搜索栏时,testArray被过滤到一个新的数组称为filteredArray。该按钮应该将该行从filteredArray移动到后跟阵列。
没有搜索,按钮按预期工作,它只在使用搜索栏时崩溃。
我在做什么错?
这里是ERROR我得到:
CustomCellSwift[1473:391841] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3600.5.2/UITableView.m:1315
新建议:filteredArray取代时莫非有什么与具有testArray的indexPath.row和followedArray冲突它表视图?
我正在使用的代码:
@IBAction func followButtonClick(_ sender: UIButton!) {
// Adding row to tag
let buttonPosition = (sender as AnyObject).convert(CGPoint.zero, to: self.myTableView)
if let indexPath = self.myTableView.indexPathForRow(at: buttonPosition) {
// Change Follow to Following
(sender as UIButton).setImage(UIImage(named: "follow.png")!, for: .normal)
cell.followButton.isHidden = true
cell.followedButton.isHidden = false
// Checking wether to import from testArray or filteredArray to followedArray
if !(searchController.isActive && searchController.searchBar.text != "") {
self.myTableView.beginUpdates()
// ----- Inserting Cell to followedArray -----
followedArray.insert(testArray[indexPath.row], at: 0)
myTableView.insertRows(at: [IndexPath(row: 0, section: 0)], with: .fade)
// ----- Removing Cell from testArray -----
testArray.remove(at: indexPath.row)
let rowToRemove = indexPath.row
self.myTableView.deleteRows(at: [IndexPath(row: rowToRemove, section: 1)], with: .fade)
self.myTableView.endUpdates()
}
else {
self.myTableView.beginUpdates()
// ----- Inserting Cell to followedArray -----
followedArray.insert(filteredArray[indexPath.row], at: 0)
myTableView.insertRows(at: [IndexPath(row: 0, section: 0)], with: .fade)
// ----- Removing Cell from filteredArray -----
filteredArray.remove(at: indexPath.row)
let rowToRemove = indexPath.row
self.myTableView.deleteRows(at: [IndexPath(row: rowToRemove, section: 0)], with: .fade)
self.myTableView.endUpdates()
}
}
}