简体   繁体   English

如何 go 关于表格视图单元格中的多个文本字段 swift

[英]How to go about multiple textfields in a tableview cell swift

I want to save some values into an array from multiple textfields in a tableview cell.我想将一些值从表格视图单元格中的多个文本字段中保存到一个数组中。 I realized my current implementation only will work if data is entered in a very specific way.我意识到我当前的实现只有在以非常特定的方式输入数据时才有效。 This is what I've tried:这是我尝试过的:

func textFieldDidEndEditing(_ textField: UITextField) {
        if(textField.tag == 1){
            self.weight = textField.text!

        } else if(textField.tag == 2){
            self.reps = textField.text!
        }
        if(self.reps != "" && self.weight != ""){
            let set = ExerciseSet(weight: self.weight, reps: self.reps, RPE: "")
            self.setsArray[setsArray.count - 1] = set
            self.weight = ""
            self.reps = ""

        }

    }

But this implementation would only work if data is entered, then the next cell is added, then entered.但是这个实现只有在输入数据时才有效,然后添加下一个单元格,然后输入。 How can I save all the data into the array by accessing each textfield in each tableview cell?如何通过访问每个 tableview 单元格中的每个文本字段将所有数据保存到数组中?

输入的数据可能是什么样子

You can create a function to loop table,get data and append ExerciseSet,您可以创建一个 function 来循环表,获取数据和 append 练习集,

func getTableData(){
        for i in 0..<tbl.numberOfRows(inSection: 0) { //tbl--> your table name
            let cell = tbl.cellForRow(at: IndexPath(row: i, section: 0)) as! TableViewCell. //TableViewCell--> your tableview custom cell name
            let set = ExerciseSet(weight: cell.txtWeight.text ?? "", reps: cell.txtReps.text ?? "", RPE: "") //txtWeight,txtReps your 2 text field names
            self.setsArray[setsArray.count - 1] = set
        }
    }

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

相关问题 带有文本字段和按钮的Tableview单元格 - Tableview cell with textfields and button 通过单击swift中的TableView单元格转到ViewController - Go to the ViewController by clicking on the TableView cell in swift 如何在swift中的动态tableView中拥有多个单元格大小? - How to have multiple cell sizes in a dynamic tableView in swift? 如何快速冻结tableView单元格? - How to freeze a tableView cell in swift? 如何在Swift iOS中以编程方式添加多个文本字段 - How to add multiple textfields programatically in swift ios Swift 4 - 以随机顺序排列的多个tableview单元格类型 - Swift 4 - Multiple tableview cell types in a random order 如何在表视图单元格中获取此表视图在Swift 4中另一个表视图控制器中的文本字段文本? - how to get textfields texts in tableview cells that this tableview is in another table view controller in swift 4? 如何在集合视图单元格Swift中检测所有OTP文本字段是否已填充 - How to detect all OTP textfields are filled or not in Collection view cell Swift Swift:从 TableView 文本字段中检索值 - Swift: Retrieving values out of TableView Textfields 如何在Swift iOS的自定义TableView单元格中向多个标签显示多个字符串值? - How can I display multiple string values to multiple labels in a custom TableView Cell in swift ios?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM