实际上,您并没有将带有已删除记录的数组保存为userdefaults。将代码更新为
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
{
if editingStyle == .delete {
if tableView == ScheduleTableView{
// Here is my code but it gives me an error, first you need to add a row with the add button
let defaults = UserDefaults.standard
var myarray = defaults.stringArray(forKey: "ScheduleArray") ?? [String]()
print(myarray)
myarray.remove(at: indexPath.row)
defaults.set(myarray, forKey: "ScheduleArray")
ScheduleTableView.deleteRows(at: [indexPath], with: .fade)
}
if tableView == GoalsTableView{
}
}
}
}
希望这有帮助。快乐的编码。