0

I have a Table view, Text field and a update Button. Table view cells count are determined by the user input in the Text field. Table view cells contains only a text field, in which user can enter some data. What I want is, I want to store the user entered data from table view cells into an array when click on that update button. How to do this? What is the best method for this?

This is the code in update button ;

@IBAction func onUpdateButtonClick(sender: AnyObject) {

            let tableViewLength = Int(productNumberTxtField.text!)! // TextField data which decides the table view cell count

            for index in 0...(tableViewLength-1)

            {
                let indexPath = NSIndexPath(forRow: index, inSection: 0)

                let cell = self.productsTableView.cellForRowAtIndexPath(indexPath) as? ProductCell

                if(cell!.productTextField.text != "") { // productTextField is the text field in cell 

                    UserDataController.sharedInstance.saveToProductsCoreData(userName, productName: (cell!.productTextField.text)!)

                }  

            }

        }
Vishnu Cyruz
  • 243
  • 1
  • 3
  • 14

1 Answers1

0

declare array

var setArray : [String] = []

first of while making textfield you have to give tag and delegate.

textfield.tag = indexPath.row
textfield.delegete = self

than in textfield delegate method

func textFieldDidEndEditing(_ textField: UITextField) {
    if(textField.text != ""){
    setArray[textField.tag] = textField.text! as String
    print(setArray)
    }
}
anshul king
  • 558
  • 4
  • 17