【发布时间】:2017-05-23 16:02:54
【问题描述】:
我在自定义单元格中有 2 个UITextfield。现在我想在从其他视图推送时将焦点设置在第一个文本字段上。
这是我在 cellForRowAt 委托中的代码,但这不起作用:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let userCell = tableView.dequeueReusableCell(withIdentifier: "InputUserInfoForm") as! InputUserInfoForm
userCell.selectionStyle = .none
userCell.fistnameTextField.autocorrectionType = .no
userCell.lastnameTextField.autocorrectionType = .no
// Firstname textfield
userCell.fistnameTextField.tag = RegisterForm.Firstname.rawValue
userCell.firstnameLabel.text = "FirstnameTitle".localized()
userCell.firstnameLabel.becomeFirstResponder()
// Lastname textfield
userCell.lastnameTextField.tag = RegisterForm.Lastname.rawValue
userCell.lastnameLabel.text = "LastnameTitle".localized()
return userCell
}
【问题讨论】:
-
你为什么要把这段代码放在
cellForRowAt?它似乎更适合viewDidAppear。
标签: ios swift uitableview uitextfield custom-cell