我在定制单元格中有2 UITextfield
。现在我想在从其他视图推送时将焦点设置在第一个文本字段上。重点定制单元格中的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'。 – toddg