简体   繁体   English

从Tableview单元格中获取更多的TextField值?

[英]Get Value more then one TextField From Tableview cell?

I have Table and First 2 Row in Textfield. 我在Textfield中有Table和First 2 Row。 I Want to get Value from Both But i how Can I get that 我想从两者中获得价值,但我如何才能得到那

Image Representation 图像表示

Code :- 代码:-

 let cell = tableView.dequeueReusableCellWithIdentifier("csttblcell", forIndexPath: indexPath)
    cell.textLabel?.text = cellTitle[indexPath.row]
    txtcontent = cell.contentView.viewWithTag(101) as! UITextField

Use something like this: 使用这样的东西:

guard let cell1 = tableView.cellForRowAtIndexPath(NSIndexPath(forItem: 0, inSection: 0)) else { return }
guard let textField1 = cell1.viewWithTag(101) as? UITextField else { return }
print(textField1.text)

Put this in your IBAction: 将其放入您的IBAction中:

let button = sender as! UIButton   // Button that called the IBAction

var labelText = ""

if let cell = button.superview!.superview {   // Cell that the button is in
    currentCell = cell as! UITableViewCell
    if let label = currentCell.textLabel {   // Get the label in that cell
        labelText = label.text   // Assign the string to our variable, declared above
    }
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
cell = tableView.dequeueReusableCellWithIdentifier("csttblcell", forIndexPath: indexPath) as! AddSubTableViewCell
cell.textLabel?.text = cellTitle[indexPath.row]
cell.Textfieldcell.tag = 10 + indexPath.row
cell.lbladd.tag = 20 + indexPath.row
}
@IBAction func btnAddData(sender: UIButton)
{
txtFname = tble_subsc.viewWithTag(10) as! UITextField
txtfdis = tble_subsc.viewWithTag(11)  as! UITextField
let fname = txtFname.text
let dis = txtfdis.text
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM