我正在使用google books api为我的应用实施条形码扫描程序。数据成功获取并存储在适当的文本字段中:
func readInJSON(controller: UIViewController, title: String, author: String, imageLink: String) {
self.titleTextField.text = title
self.authorTextField.text = author
}
然而,文本实际上并没有出现在textFields中,直到我点击它们,然后文本填充。我想知道是否有某种方法可以在没有用户点击文本字段本身的情况下显示文本。
答案 0 :(得分:2)
也许你不在主线上。 UI操作应该在主线程上完成。 试试这个
dispatch_async(dispatch_get_main_queue()) {
self.titleTextField.text = title
self.authorTextField.text = author
}