swift - 使用 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 方法?
解决方案
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!)
推荐阅读
- django - 如何使用 django crispy-forms 在字段中添加占位符文本
- abaqus - abaqus中如何导出全局载荷向量
- docker - 我可以在 Windows Server 2019 中运行 NVIDIA DeepStream SDK 吗?
- oracle-apex - 如何在 Oracle Apex 中实现悲观锁定
- plotly - 情节问题
- haskell - foldMap 连体
- amazon-web-services - 如何使用 Python-AWS lambda 中的返回对象?
- flutter - 是否可以在颤动中使用 FFMPEG 将 2 个视频合并为一个视频
- shopify - 使用 Shopify API 计算总销售额
- c# - 如何修复我的冲刺在跳跃时无法正常工作以及如何添加冷却时间?