2016-08-17 36 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 
    } 
} 
相關問題