如何调用 UITableViewCell 内部的 textField (swift)
How to call textField that is a inside of UITableViewCell (swift)
我有一个 UITextField
在 UITableViewCell
:
里面
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! TextFieldTableViewCell
let textField: UITextField = cell.textField
let detail = self.detailItem
textField.text = detail!.valueForKey("name")!.description + detail!.valueForKey("number")!.description
print()
return cell
}
如何将相同的文本字段传递给:
func textFieldDidBeginEditing(textField: UITextField) {
print("executed")
let detail = self.detailItem
let textField: UITextField = self.text.textField
if (textField.text != detail!.valueForKey("name")!.description + detail!.valueForKey("number")!.description) {
detail?.setValue(textField.text, forKey: "name")
}
}
已解决
我需要在其定义后添加 textField.delegate = self
。
我假设它将视图连接到视图控制器,允许它看到 textFieldDidStopEditing
函数。
你需要在 cellForRowAtIndexPath 方法本身给 UITextFieldDelegate 方法
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! TextFieldTableViewCell
let textField: UITextField = cell.textField
textField.delegate = self
let detail = self.detailItem
textField.text = detail!.valueForKey("name")!.description + detail!.valueForKey("number")!.description
return cell
}
我有一个 UITextField
在 UITableViewCell
:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! TextFieldTableViewCell
let textField: UITextField = cell.textField
let detail = self.detailItem
textField.text = detail!.valueForKey("name")!.description + detail!.valueForKey("number")!.description
print()
return cell
}
如何将相同的文本字段传递给:
func textFieldDidBeginEditing(textField: UITextField) {
print("executed")
let detail = self.detailItem
let textField: UITextField = self.text.textField
if (textField.text != detail!.valueForKey("name")!.description + detail!.valueForKey("number")!.description) {
detail?.setValue(textField.text, forKey: "name")
}
}
已解决
我需要在其定义后添加 textField.delegate = self
。
我假设它将视图连接到视图控制器,允许它看到 textFieldDidStopEditing
函数。
你需要在 cellForRowAtIndexPath 方法本身给 UITextFieldDelegate 方法
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! TextFieldTableViewCell
let textField: UITextField = cell.textField
textField.delegate = self
let detail = self.detailItem
textField.text = detail!.valueForKey("name")!.description + detail!.valueForKey("number")!.description
return cell
}