我需要帮助删除核心数据中的一行
大纲:
我有一个 TableView ,它是从一个表单中填充的,该表单要求用户输入有关 friend 的详细信息。
用户需要一个从列表中删除好友的选项。当用户单击 TableView 中的一行时,我需要访问该字符串以获取 ID,然后查询该 ID 的核心数据,然后将其删除。
我坚持访问用户点击的数据并获取 ID
这是表格 View 中 friend 的样子
12345 James Bond 19 Male Sydney ICT
其中 12345 是唯一的学号
这是我从核心数据中删除 friend 的功能
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
tableView.delegate = self
tableView.dataSource = self
let appDelegate = UIApplication.shared.delegate as! AppDelegate
friends = appDelegate.getFriendInfo()
self.tableView.rowHeight = 33.0
}
}
我在获取行内的 ID 然后从核心数据中删除该行时遇到困难
最佳答案
使用给定的 indexPath 从数组中检索 id
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let id = friends[indexPath.row].studentID
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.removeRecord(id: id)
}
关于ios - 访问核心数据以快速返回第一个单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64364792/