2016-08-17 57 views
0

我有文本框中的表和前两行。我想从两个获得的价值,但我我怎样才能像从Tableview单元格获取超过一个TextField的值?

Image Representation

代码: -

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

这只是'cellForRowAtIndexPath'方法。你想在哪里获得价值?你的问题不清楚。 –

+0

我需要从文本框的按钮上获取值Action –

+0

你使用静态表吗? –

回答

0
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 
} 
1

使用这样的事情:

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) 
1

在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 
    } 
} 
相关问题