简体   繁体   English

UITextField上存储的领域数据为空,print(entry)有效

[英]Realm data stored on UITextField are empty, print(entry) works

I have a Realm database, in which I store my entries. 我有一个Realm数据库,用于存储我的条目。 Storing & querying work without any problems. 存储和查询工作没有任何问题。 I know in Swift Realm Results are lazy but I can't get why this is happening. 我知道在Swift Realm中结果是懒惰的,但我不知道为什么会这样。 My code: 我的代码:

newsItems = databaseHelper.retriveAllNews()
//[...] this is on tableView method
let currentNew = newsItems[indexPath.row]
print(currentNew)
newsCell.newsTitle.text = currentNew.title
newsCell.newsText.text = currentNew.info

the print(..) statement works perfectly and I get all the info stored in the currentNew object, but when I set the info into the UITextField newsCell.newsTitle & newsCell.newsText them are displayed empty, as the Result have not been loaded yet. print(..)语句可以完美工作,并且我将所有信息存储在currentNew对象中,但是当我将信息设置到UITextField newsCell.newsTitlenewsCell.newsText中时,由于结果尚未加载,它们显示为空。 。
Any suggestion? 有什么建议吗?

The most likely cause of the problem you're seeing is omitting the dynamic modifier from the property declarations in your model class. 您看到的问题的最可能原因是从模型类的属性声明中省略了dynamic修饰符。 The dynamic modifier is necessary to ensure that Realm has an opportunity to intercept access to the properties, giving Realm an opportunity to read / write the data from the file on disk. dynamic修饰符对于确保Realm有机会拦截对属性的访问是必要的,从而使Realm有机会从磁盘上的文件读取/写入数据。 Omitting these properties results in the Swift compiler accessing the instance variables directly, cutting Realm out of the loop. 省略这些属性会导致Swift编译器直接访问实例变量,从而使Realm脱离循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM