简体   繁体   English

从动态tableview中的textfield获取文本并将其插入数组swift中

[英]get text from textfield in dynamic tableview and insert it in array swift

I am trying to get the text from textfield in dynamic tableview so thats mean i have one or more textfield i tried this but its not working 我正在尝试从动态Tableview中的文本字段中获取文本,因此这意味着我尝试了一个或多个文本字段,但它无法正常工作

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

    coursesGrade.insert(cell.grade.text!, at: indexPath.row)

    return cell
}

You should use textField.tag and textFieldDidBeginEditing delegate of UITextFieldDelegate 您应该使用UITextFieldDelegate textField.tagtextFieldDidBeginEditing委托

make a array to storing textfield text. 创建一个数组来存储文本字段文本。 for every textField that added to table you have to add an empty value in array data and set table indexPath.row as textField.tag 对于添加到表中的每个textField ,您必须在数组数据中添加一个空值并将表indexPath.row设置为textField.tag

so in textFieldDidBeginEditing delegate you have access to textField.tag and you can store textField.text to data[textField.tag] array. 因此,在textFieldDidBeginEditing委托中,您可以访问textField.tag并且可以将textField.text存储到data[textField.tag]数组。

there are a lot of ways to make it work. 有很多方法可以使其工作。 It's one of that ways ;-) 这是其中一种;-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM