2016-08-17 1 views
0

Ich habe Tabelle und erste 2 Zeile in Textfield. Ich wünsche Wert von beiden zu erhalten, aber ich Wie kann ich dasWert erhalten mehr als ein TextField From Tableview-Zelle?

Image Representation

Code: -

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

Dies ist nur 'cellForRowAtIndexPath' Methode. Wo willst du Wert haben? Deine Frage ist unklar. –

+0

Ich brauche einen Wert von Textfeld auf Schaltfläche Aktion –

+0

Verwenden Sie eine statische Tabelle? –

Antwort

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

Verwendung so etwas wie dieses:

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

Setzen Sie diese in Ihrem 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 
    } 
}