gpt4 book ai didi

swift - 如何通过set函数删除我喜欢删除到UserDefaults的indexPath.row

转载 作者:行者123 更新时间:2023-11-30 12:03:54 25 4
gpt4 key购买 nike

我删除了一行,并且想在数据管理器中删除它,如何传递要在索引路径中删除的行?

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete{

self.tableView.beginUpdates()

print("Deleted was pressed")

records.remove(at: indexPath.row)

tableView.deleteRows(at: [indexPath], with: .automatic)

// DataManager.getInstance().setNewRecord(array: [UserRecordDataManager])
// DataManager.getInstance().setNewRecord(array: UserRecordDataManager)
self.tableView.endUpdates()
tableView.reloadData()
print(records.count)

}
}

/// Data Manager- doing the SET option

public func setNewRecord(array: [UserRecordDataManager] ){

records.remove=???
self.records = getRecords()
print(DataManager.getInstance().records.count)

}

最佳答案

in the data manager:

public func removeRecord(index: Int){
if getRecords().isEmpty{
print("ERROR - there is no recoreds")
return
}else{
self.records = getRecords()
self.records.remove(at: index)

let encodeData = NSKeyedArchiver.archivedData(withRootObject: self.records)
UserDefaults.standard.set(encodeData, forKey: "records")
}
}




in the tableview:

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete{

self.tableView.beginUpdates()

print("Deleted was pressed")

let index = indexPath.row

records.remove(at: index)

print(index)
tableView.deleteRows(at: [indexPath], with: .automatic)
DataManager.getInstance().removeRecord(index: index)

self.tableView.endUpdates()
tableView.reloadData()
print(records.count)

}

关于swift - 如何通过set函数删除我喜欢删除到UserDefaults的indexPath.row,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46884289/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com