Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在tableview单元格中处理多个文本字段_Ios_Swift_Uitableview_Uitextfield - Fatal编程技术网

Ios 如何在tableview单元格中处理多个文本字段

Ios 如何在tableview单元格中处理多个文本字段,ios,swift,uitableview,uitextfield,Ios,Swift,Uitableview,Uitextfield,我想将tableview单元格中多个文本字段中的一些值保存到数组中。我意识到,只有以非常具体的方式输入数据,我当前的实现才会起作用。这就是我尝试过的: func textFieldDidEndEditing(_ textField: UITextField) { if(textField.tag == 1){ self.weight = textField.text! } else if(textField.tag == 2){

我想将tableview单元格中多个文本字段中的一些值保存到数组中。我意识到,只有以非常具体的方式输入数据,我当前的实现才会起作用。这就是我尝试过的:

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 = ""

        }

    }
但只有在输入数据,然后添加下一个单元格,然后输入数据时,此实现才会起作用。如何通过访问每个tableview单元格中的每个文本字段将所有数据保存到数组中


您可以创建一个函数来循环表、获取数据和附加ExerciseSet

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
        }
    }

您可以创建一个函数来循环表、获取数据和附加ExerciseSet

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
        }
    }

这正是我需要的谢谢你。我不知道你能那样看你的桌子!这正是我需要的谢谢你。我不知道你能那样看你的桌子!