我在这里使用 Eureka forms swift 库:Eureka forms
我想让我的输入表单的第一行成为每次视图出现时的第一响应者。我尝试添加一个 .cellUpdate 回调,该回调在每次视图出现时触发,并执行 cell.becomeFirstResponder() 但这不起作用。有这个图书馆经验的人可以帮忙吗?谢谢。
我在这里使用 Eureka forms swift 库:Eureka forms
我想让我的输入表单的第一行成为每次视图出现时的第一响应者。我尝试添加一个 .cellUpdate 回调,该回调在每次视图出现时触发,并执行 cell.becomeFirstResponder() 但这不起作用。有这个图书馆经验的人可以帮忙吗?谢谢。
尝试这个
import UIKit
import Eureka
class ViewController3: FormViewController {
override func viewDidLoad() {
super.viewDidLoad()
form +++ Section("Custom cells")
<<< TextRow("TextRow"){_ in
}
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
let row = self.form.rowByTag("TextRow") as! TextRow
row.cell.textField.becomeFirstResponder()
}
}
我希望这可以帮助你
钩在cellSetup中,这样我们就不需要在viewDidAppear中查找cell了
form +++ Section("")
<<< TextRow() {
$0.title = "Name"
$0.value = list?.name ?? ""
$0.cellSetup() { cell, row in
cell.textField.becomeFirstResponder()
}
$0.onChange() {
self.list.name = $0.value ?? ""
}
}
受 Reinier 回答的启发,这是另一种对我有用的方法。
设置表单时直接调用$0.cell.textField.becomeFirstResponder()。
form +++ Section()
<<< ZipCodeRow() {
$0.value = postal_code
$0.cell.textField.becomeFirstResponder()
}
斯威夫特 4:
在 ViewDidLoad() 中添加:
let row = self.form.rowBy(tag: "TextRow.tag") as! TextRow
row.cell.textField.becomeFirstResponder()