2016-08-17 9 views
0

私はテーブルと最初の2行をテキストフィールドに持っています。私は両方から値を取得したいが、私はどのように私は値を1つ以上取得TextField Tableviewセルから?

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

ボタンのテキストフィールドから値を取得する必要があります。アクション –

+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 
    } 
} 
関連する問題