如何解决每当我运行我的应用程序时,我的Realm属性不会更新
伙计们,所以我开发了NoteApp,想要的行为是,每当用户点击其中一个单元格时,就会出现一个选中标记,如果再次点击,该选中标记就会消失。 这是我的代码。
Item.swift
class Item: Object {
@objc dynamic var title: String?
@objc dynamic var done: Bool = false
}
ViewController.swift
var toDoItems: Results<Item>!
func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell",for: indexPath)
cell.textLabel?.text = toDoItems[indexPath.row].title
cell.accessoryType = toDoItems[indexPath.row].done ? .checkmark : .none
return cell
}
func tableView(_ tableView: UITableView,didSelectRowAt indexPath: IndexPath) {
try! realm.write {
toDoItems![indexPath.row].done = !toDoItems![indexPath.row].done
}
tableView.reloadData()
tableView.deselectRow(at: indexPath,animated: true)
}
所以问题是,每当我点击一个单元格时,勾号都不会出现,并且Realm Studio中的我完成的领域属性保持不变。请帮忙!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。