领域+ NSTableView + NSArrayController [英] Realm + NSTableView + NSArrayController
问题描述
我的macOS应用程序存在一些问题,希望您能为我提供帮助. 我在macOS上还很新,所以请保持亲切;)
i have some Problems with my macOS Application and hope you can help me. Im pretty new on macOS so please be nice ;)
该应用程序的一部分由一个简单的NSTableView组成,其内容已绑定到NSArrayController. NSArrayController是从领域数据库提供的.
A part of the app consists of a simple NSTableView which content is binded to an NSArrayController. The NSArrayController is feeded from a realm database.
如您所见,每行都有一个复选框,应在realm对象中设置bool值.
As you can see there is a checkbox for each row, which should set the bool value in the realm object.
绑定是可以的,因此,如果我标记/取消标记复选框,则似乎尝试在领域对象上进行写操作. 但是,由于领域需要一个不会被触发的活动写事务,因此它会崩溃.
The bindings are ok, so if I mark/unmark the checkbox it seems to try writing on the realm object. But since realm needs a active write transaction, which will not be triggered, it crashes.
我的问题是: 如何在具有表视图绑定的领域对象上书写? 有任何想法吗 ?
My Question is: How can I write on realm objects with table view bindings ? Any ideas ?
推荐答案
您可以尝试将以下内容添加到模型对象(Realm对象)中:
You could try to add the following to your model object (the Realm object) :
override func setValue(_ value: Any?, forKey key: String) {
try! realm?.write {
self.mySetValue(value, forKeyPath: key) // bug in swift preventing directly calling super here
}
}
private func mySetValue (_ value: Any?, forKeyPath key: String) {
super.setValue(value, forKey: key)
}
这篇关于领域+ NSTableView + NSArrayController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!