gpt4 book ai didi

ios - 如何将 UITableViewCell 中 textField 的值获取到 textFieldDelegate 方法 shouldChangeCharactersIn 中?

转载 作者:行者123 更新时间:2023-11-28 13:51:54 28 4
gpt4 key购买 nike

我有一个带有 textFields 的 tableViewCell。当文本字段中的字符发生变化时,我想为单个文本字段获取一个值。那么如何获取所有文本字段的文本字段值

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {


var arrChanged : NSMutableArray = []


for i in 0..<arrCheckList.count{
let indexPath = IndexPath(row: i, section: 0)
let cell: CheckInCell = tblViewCheckIn.cellForRow(at: indexPath) as! CheckInCell

if(textField.text?.count != 0){
let dictData = (arrCheckList.object(at: cell.txtQty.tag) as! NSDictionary).mutableCopy() as! NSMutableDictionary
dictData.setValue(cell.txtQty.text, forKey: "check_list_qty")

arrChanged.add(dictData)
}

}

arrCheckList = arrChanged

return true
}

最佳答案

使用下面的代码获取完整的text field里面的text should change characters:

 var str:NSString = textField.text! as NSString
str = str.replacingCharacters(in: range, with: string) as NSString

要获取特定的文本字段,您可以在行的单元格中设置标签,在这里您可以检查文本字段标签以识别文本字段。

在行集的单元格中:

    cell.textField.tag = indexPath.row

然后在应该改变范围内的字符

  array[textfield.tag] = str //which is the textfieldvalue

所以在这里您可以根据 TableView 行索引存储文本字段值。

关于ios - 如何将 UITableViewCell 中 textField 的值获取到 textFieldDelegate 方法 shouldChangeCharactersIn 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54492289/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com