如何将 UITableViewCell 中 textField 的值获取到 textFieldDelegate 方法 shouldChangeCharactersIn 中?
How to get value of textField in UITableViewCell into textFieldDelegate Method shouldChangeCharactersIn?
我有一个带有文本字段的 tableViewCell。当文本字段中的字符发生变化时,我想为单个 textField 获取一个值。那么我怎样才能获得所有文本字段的文本字段值
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
}
使用以下代码获取文本字段中的完整文本,里面应该改变字符:
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
所以在这里您可以根据表视图行索引存储文本字段值。
我有一个带有文本字段的 tableViewCell。当文本字段中的字符发生变化时,我想为单个 textField 获取一个值。那么我怎样才能获得所有文本字段的文本字段值
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
}
使用以下代码获取文本字段中的完整文本,里面应该改变字符:
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
所以在这里您可以根据表视图行索引存储文本字段值。