删除tableview上的行返回不正确的行数据

时间:2017-11-07 12:29:58

标签: ios iphone swift uitableview

我一直在尝试创建一个删除功能,一起从文档目录中删除数据和文件,然后更新行数据。

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
    if editingStyle == .delete {
        // Delete the row from the data source
        try! FileManager.default.removeItem(at: fileURLs[indexPath.row])
        fileURLs.remove(at: indexPath.row)
        print(indexPath.row)
        tableView.deleteRows(at: [indexPath], with: .fade)

        //tableView.reloadData()
    } else if editingStyle == .insert {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }
}

但每次删除文件时,它似乎都正确地从目录中删除了该文件,但是tableview似乎未正确更新。例如

如果我已经拥有1个文件并将其删除并创建一个新文件,则新文件将始终尝试按名称打开不存在的文件。

0 个答案:

没有答案