【发布时间】:2017-04-17 02:24:00
【问题描述】:
我的问题是我在可扩展表格视图中有一个文本字段,它由 cellDescription plist 决定。在这个表格视图中,当地址部分展开时,会弹出一个文本字段,用户可以在其中输入地址。用户必须在键盘上按回车键(或回车键)才能保存地址。我想知道是否有一种方法可以检测文本字段的变化,可以不断更新文本字段的值,这样用户就不必输入回车来保存地址。下面是我的代码当前的结构,但我很困惑,因为文本字段不在常规视图控制器内,而是在外部 xib 文件中。
func configureTableView() {
tblExpandable.delegate = self
tblExpandable.dataSource = self
tblExpandable.tableFooterView = UIView(frame: CGRect.zero)
tblExpandable.register(UINib(nibName: "TextfieldCell", bundle: nil), forCellReuseIdentifier: "idCellTextfield")
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let currentCellDescriptor = getCellDescriptorForIndexPath(indexPath)
let cell = tableView.dequeueReusableCell(withIdentifier: currentCellDescriptor["cellIdentifier"] as! String, for: indexPath) as! CustomCell
if currentCellDescriptor["cellIdentifier"] as! String == "idCellTextfield" {
cell.textField.placeholder = currentCellDescriptor["primaryTitle"] as? String
valueOfInterest = cell.textField.text!
}
cell.delegate = self
return cell
}
func textfieldTextWasChanged(_ newText: String, parentCell: CustomCell) {
let parentCellIndexPath = tblExpandable.indexPath(for: parentCell)
var address = ""
address = "\(newText)"
((cellDescriptors[0] as! NSMutableArray)[11] as AnyObject).setValue(address, forKey: "primaryTitle")
location = (((cellDescriptors[0]) as! NSMutableArray)[11] as! NSDictionary)["primaryTitle"]! as! String
tblExpandable.reloadData()
}
【问题讨论】:
标签: swift tableview xib textfield