ios - 编辑(文本字段而非表格)结束时如何跳转到 TableView 的下一个单元格中的 UITextField
问题描述
我正在编写一个具有固定大小表和每个单元格中的几个 UITextFields 的应用程序。用户需要在文本字段中输入数据,我想在当前文本字段的编辑停止后自动跳转到下一个文本字段。
我在 TableViewCell 类中有以下代码(从 stackoverflow 上的其他地方修改),它可以很好地跳转到单元格中的下一个字段,但不会跳转到下一个单元格。
func textFieldDidEndEditing(_ textField: UITextField) {
// Try to find next responder
if let nextField = textField.superview?.viewWithTag(textField.tag + 1) as? UITextField {
nextField.becomeFirstResponder()
} else {
textField.resignFirstResponder()
}
return
}
我意识到这是因为在第二次编辑之后,下一个文本字段不在同一个单元格中,但我不知道如何处理下一个单元格中的文本字段以使其成为 FirstResponder。我在单元格中的文本字段上有一个观察者来检查更改并更新数组:
@IBAction func updatePs(_ sender: Any) {
psChanged?(ps.text ?? "0")
}
这是在 UITableView cellForRowAt 函数中的位置:
cell.psChanged = { value in
self.psP[indexPath.row] = Int(value) ?? 0
}
我虽然使用这个观察者来改变 UITableView cellForRowAt 函数中的 FirstResponder ,但我不知道如何去做。
PS 我知道在表格中使用标签可能会出现问题,但表格是固定大小的,无法删除行。
解决方案
推荐阅读
- node.js - NodeJS+Express循环调用异步方法
- python - PySFTP 和 get_r 使用 Python - “没有这样的文件或目录”
- ios - 即使变量被硬编码,BMI 应用程序打印结果也是 0
- aem - 找出 Adobe Experience Manager 上次重新启动时间
- javascript - 强制更改标题元素上的文本
- python-2.7 - 如何在 python2 环境中安装 Bazel?
- javascript - 为什么标签显示在选择框内?
- testng - 我们应该在 TestNg DataProviders 中调用 API 吗?
- c# - 如何将 ObjectHandle 从 Pkcs11Interop 转换为 X509 证书或 Pem 格式?
- html - 无法将字体用于自定义字体