A
A
arturios5712017-08-26 22:19:10
Swift
arturios571, 2017-08-26 22:19:10

How to collect data from all TextField?

Good day everyone!
Problem essence following:
There is a table with a cell in cells 2 TextField. The user himself creates the number of cells by clicking on the Add button (a new cell appears in the table with text fields) and so the number of cells can be N. Also in the table itself there is a Create button (it is always right below the cells) as by clicking on Create Take away all the data that the user entered and, for example, save them to an array.
an array of type let array = [String]() where 0 index in the array is the data from the cell at index 0, etc.
I don’t quite understand how to pick up data, I tried to fly an instance of the cell class in the table class and pick up data through it from the text fields, but it comes nil.
Thanks for the tips
Here's what it looks like
g.recordit.co/KTulGfnWjU.gif53785ea38255426fb608bce394f05d78.gif

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Tikhonov, 2017-08-26
@tikhonov666

First, you can simply put IBOutlets next to the cell, i.e.

@IBOutlet var textFiled1: UITextFiled!
@IBOutlet var textFiled2: UITextFiled!

And you also hang up Action on pressing the button, also in the cell class.
You may have a problem when you have a lot of cells in the table, then they will be reused and the text entered in the text field will be overwritten. The solution is to store the entered text in a variable or refuse to place text fields in cells.
Retrieving data is quite simple .
@IBAction func buttonTapped(sender: Any) { 
    var text1 = textField1.text
    array.append(text1) // если нужно добавить в массив
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question