我正在使用带有uitextfield的单个单元格来显示包含用户名,电子邮件ID,电话号码的表单。但是我想在按下下一个按钮的同时将光标移动到下一个字段。
我正在使用这样的代码:
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
let userNameCell = self.profileManagement!.cellForRow(at: IndexPath(row: 0, section: 0)) as? RegistrationFieldTableViewCell!
let emailIDCell = self.profileManagement!.cellForRow(at: IndexPath(row: 1, section: 0)) as? RegistrationFieldTableViewCell!
if textField == userNameCell {
textField.resignFirstResponder()
emailIDCell?.becomeFirstResponder()
return false
} else if textField == emailIDCell {
textField.resignFirstResponder()
return false
}
return true
}
索引路径代码行的单元格如下:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// create a new cell if needed or reuse an old one
let regCell = profileManagement.dequeueReusableCell(withIdentifier:"regFirstCell", for: indexPath)as? RegistrationFieldTableViewCell
regCell?.registrationField.tag = indexPath.row
regCell?.registrationFieldImage.image = fieldImages[indexPath.row]
let nameFields = NSLocalizedString( regFieldsNames[indexPath.row], comment: "")
regCell?.registrationField.placeholder = nameFields
regCell?.registrationField.autocorrectionType = .no
regCell?.registrationField.keyboardType = UIKeyboardType.default
regCell?.showPassword.isHidden = true
//Swith case for giving keypad to textfields
switch indexPath.row {
case 0:
regCell?.registrationField.text = self.name
regCell?.registrationField.isSecureTextEntry = false
case 1:
regCell?.registrationField.text = self.emailId
regCell?.registrationField.textColor = UIColor.black
regCell?.registrationField.isUserInteractionEnabled = true
case 2:
regCell?.registrationField.text = self.civilId
regCell?.registrationField.textColor = UIColor.lightGray
regCell?.registrationField.isUserInteractionEnabled = false
case 3:
regCell?.registrationField.text = "+965 \(self.phoneNumber)"
regCell?.registrationField.isUserInteractionEnabled = false
case 4:
regCell?.registrationField.isSecureTextEntry = true
regCell?.registrationField.text = "abhijith123"
regCell?.showPassword.isHidden = true
regCell?.registrationField.isUserInteractionEnabled = false
default:
print("Something else")
}
return regCell!
}
但是当按下键盘上的下一个按钮时,它不会切换到下一个文本字段。为什么会这样?我的代码出了什么问题?