首页 > 解决方案 > 使用 EntryView() 的 setValue 而不是 setPlaceholder

问题描述

我将应用程序中 EntryView() 的占位符值设置为从数据库中检索的值。但是现在我想改变我的方法,而是设置 EntryView 的值,这样用户就不必填写内容。

这是我检索值然后设置占位符的代码:

let firstName = dict["firstName"] as? String 

...

self.firstNameEntryView.setPlaceholder(firstName!)

此功能工作正常,它填充正确的值作为占位符。但是如何将“firstName”的字符串值设置为我的 firstNameEntryView 中的实际值?

我尝试了这种方法:

self.firstNameEntryView.setValue(String?.self, forKey: firstName!)

但是我收到了这个错误:“ setValue:forUndefinedKey:]: 这个类对于键 Thomas 不是键值编码兼容的”

Thomas 是我数据库中的正确值。我是否错误地使用了 setValue 方法?

标签: swiftio

解决方案


I ended up figuring this out through trial and error.

The code to set the text is as follows:

self.firstNameEntryView.textField.text?.append(firstName!)

推荐阅读