Сбой приложения с self.tableView.deleteRows (at: [indexPath], with: .fade) - PullRequest
0 голосов
/ 08 января 2020

Прикладная часть удаляет файл, но также вылетает при сообщении об ошибке

объявленная часть

var FileContent = (try? FileManager.default.contentsOfDirectory(atPath : newpath.first!))
var SingleUrl = newpath.first!
//MARK:- viewcontroller extension Deleting file from directory
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
    if editingStyle == .delete {
    try! FileManager.default.removeItem(atPath: SingleUrl + "/" + FileContent![indexPath.row])
    self.tableView.deleteRows(at: [indexPath], with: .fade)
    }

сообщение об ошибке ............

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (5) must be equal to the number of rows contained in that section before the update (5), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'

1 Ответ

0 голосов
/ 08 января 2020

Вам нужно удалить из массива не только файл

try! FileManager.default.removeItem(atPath: singleUrl + "/" + fileContent![indexPath.row]) 
fileContent!.remove(at:indexPath.row)
self.tableView.deleteRows(at: [indexPath], with: .fade)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...