从TextFields读取输入

时间:2019-01-07 07:51:04

标签: ios swift uitableview uitextfield

我试图从多个TableViewCell的2文本字段读取输入,看起来它仅访问input2并将input2两次附加到inputRead数组。我该如何解决?非常感谢

P / S:这是我在单元格中布局2个TextField的方式:[input1] [input2]

override func tableView(_ tableView: UITableView, cellForRowAt 
indexPath: IndexPath) -> UITableViewCell {
    let customCell = tableView.dequeueReusableCell(withIdentifier:  "CustomCell") as! CustomCell

    customCell.input1.tag = indexPath.row
    customCell.input2.tag = indexPath.row
    customCell.input1.delegate = self
    customCell.input2.delegate = self

    return customCell
} 

func textFieldShouldReturn(_ textField: UITextField) -> Bool {
    return textField.endEditing(true)
}

func textFieldDidEndEditing(_ textField: UITextField) {
    let indexPath = IndexPath(row: textField.tag, section: 0)
    if let customCell = self.table.cellForRow(at: indexPath) as? 
    CustomCell {

        let string1 = String(customCell.input1.text!)
        let string2 = String(customCell.input2.text!)
        inputRead.append(input(string1, string2))
    }

}//end class

class CustomCell : UITableViewCell{
    @IBOutlet weak var input1: UITextField!
    @IBOutlet weak var input2: UITextField!
}

0 个答案:

没有答案