Я использую Xcode 8 и быстры 3.Swift 3.0 Невозможно удалить строки из UITableView
Я получаю ошибки подтверждения, когда я пытаюсь удалить строки из UITableView.
недостаточность Assertion в - [UITableView _endCellAnimationsWithContext:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3599.5/UITableView.m:1610
Нагрузочного приложение из-за uncaught exception «NSInternalInconsistencyException», причина: «Неверное обновление: недопустимое количество строк в разделе 0. Количество строк, содержащихся в существующем разделе после обновления (25), должно быть равно количеству строк, содержащихся в этом разделе, перед обновлением (25), плюс или минус количество строк, вставленных или удаленных из этого раздела (0 вставлено, 1 удалено) и плюс или минус количество строк, перемещенных в или из этого раздела (0 перемещен, 0 перемещен).
Код:
// create a cell for each table view row
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// create a new cell if needed or reuse an old one
let cell:UserCell = self.tableView.dequeueReusableCell(withIdentifier: "tblCell") as! UserCell!
cell.titleLabel.text = self.animals[(indexPath as NSIndexPath).row]
cell.btnDelete.addTarget(self, action:#selector(ViewController.buttonClicked(sender:)), for: UIControlEvents.touchUpInside);
return cell
}
func buttonClicked(sender:UIButton) {
if let superview = sender.superview {
if let cell = superview.superview as? UserCell {
if let indexPath = self.tableView.indexPath(for: cell){
print("row = ",indexPath.row)
self.tableView.beginUpdates()
self.tableView.deleteRows(at: [indexPath], with: .left)
self.tableView.endUpdates()
self.animals.remove(at:indexPath.row)
}
}
}
}
Я только начал изучать стрижа так, пожалуйста, помогите мне.
источник данных должен быть обновлен до завершения обновлений. Попробуйте вызвать 'self.animals.remove (at: indexPath.row)' before' self.tableView.endUpdates() ' – akdsouza
Возможный дубликат [iOS8 Swift: deleteRowsAtIndexPaths crashes] (http://stackoverflow.com/questions/25588779/ ios8-swift-deleterowsatindexpaths-crashes) – pedrouan
@pedrouan "deleteRowsAtIndexPaths" нет в swift 3. –