使用 TPKeyboardAvoiding TableView 时如何访问表视图单元格内的文本字段值

How to acces textfield values inside tableview cell when using TPKeyboardAvoidingTableView

我已经集成了 TPKeyboardAvoidingTableView 来处理文本字段的下一个响应者。我如何访问文本字段值,因为我无法分配文本字段委托。

func textFieldDidEndEditing(_ textField: UITextField) {
        if textField.tag == UserDetails.Name.rawValue{
            name = textField.text!
            print(name)
        }
        else if textField.tag == UserDetails.Mobile.rawValue{
            mobile = textField.text!
            print(mobile)
        }
        else if textField.tag == UserDetails.Qualification.rawValue{
            qualification = textField.text!
            print(qualification)
        }
        else if textField.tag == UserDetails.Area.rawValue{
            area = textField.text!
            print(area)
        }
    }

不是最好的方法,但应该可行:

func textFieldShouldReturn(_ textField: UITextField) -> Bool {
    var indexPath: IndexPath?
    if (textField.superview?.superview is YourCell) {
        let cell = textField.superview?.superview as? UITableViewCell
        indexPath = tableView.indexPath(for: cell)
    }
    let indexPathNextRow = IndexPath(row: indexPath?.row + 1, section: indexPath?.section ?? 0)
    let cellNextRow = (tableView.cellForRow(at: indexPathNextRow) as? YourCell) as? YourCell
    let tag = Int(indexPathNextRow.row)
    let textFieldNextRow = cellNextRow?.contentView.viewWithTag(tag) as? UITextField
    textFieldNextRow?.becomeFirstResponder()
    print("last text field---------->\(Int(textField.tag))")
    return true
}

func textFieldDidEndEditing(_ textField: UITextField) {
    textValues[textField.tag] = textField.text ?? ""
}  

不要忘记为单元格设置标签 UITextField