如何从表视图单元格内的文本字段中获取文本值? [英] how to get text value from inside text field inside table view cell?
本文介绍了如何从表视图单元格内的文本字段中获取文本值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请查看我的代码
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
let textin = UITextField()
textin.text = "value"
cell.addSubview(textin)
let Btin = UIButton()
Btin.tag = indexPath.row
Btin.addTarget(self, action:#selector(printC(_:)), for: UIControlEvents.touchUpInside)
cell.addSubview(Btin)
return cell
}
@objc func printC(_ sender: UIButton){
}
我想要点击 Btin 我可以(git文本字段值) textin 由func printC
i want when i click on Btin i can ( git text field value ) of textin by func printC
推荐答案
您可以使用临时变量来存储textfield的值。
You can take a temp variable, to store the value of textfield.
var temp : String!
var tempLbl : UILabel!
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
let textin = UITextField()
textin.text = "value"
temp = textin.text
cell.addSubview(textin)
let Btin = UIButton()
Btin.tag = indexPath.row
Btin.addTarget(self, action:#selector(printC(_:)), for: UIControlEvents.touchUpInside)
cell.addSubview(Btin)
return cell
}
@objc func printC(_ sender: UIButton){
tempLbl.text = temp
}
试试这个,希望这样可行。
Try this one, hope this will work.
这篇关于如何从表视图单元格内的文本字段中获取文本值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文