【问题标题】:Get Value more then one TextField From Tableview cell?从 Tableview 单元格中获取超过一个 TextField 的值?
【发布时间】:2016-08-17 12:34:02
【问题描述】:

我在文本字段中有表格和前 2 行。我想从两者中获得价值,但我怎样才能获得呢

Image Representation

代码:-

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

【问题讨论】:

  • 这只是cellForRowAtIndexPath 方法。你想从哪里获得价值?您的问题不清楚。
  • 我需要从按钮操作上的文本字段中获取价值
  • 你使用静态表吗?
  • 是的,我想从 tableview 中的 textfield 获取数据并将数据存储在数据库中,以便两个不同的 textfield 数据都需要存储在不同的变量中
  • 谢谢大家解决我的问题

标签: ios swift uitableview uitextfield


【解决方案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
    }
}

【讨论】:

    【解决方案2】:
    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
    }
    

    【讨论】:

      【解决方案3】:

      使用这样的东西:

      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)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-05-12
        • 1970-01-01
        • 2013-02-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多