我有一个应用程序,它可以分栏,并允许用户将项目添加到特定的栏。例如,用户可以将“洗车”添加到星期一的栏中。我现在遇到了删除功能无法工作的问题,这样用户就可以删除他们误加或完成的项目。到目前为止,我所做的要么给我一个“类型转换值错误”,要么是“索引超出范围”错误。我想知道这是否是删除项目的正确方法,或者是否有不同的方法。
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == UITableViewCellEditingStyle.delete {
//list.remove(at: indexPath.row)
list.remove(at: [[indexPath.row]] as Any as! Int)
UserDefaults.standard.set(list, forKey: "list")
tableView.reloadData()
}
}