Gerardo
Gerardo

Reputation: 5830

Iphone Cells with Text Field in TableView

i have a table view in which each cell has a TextField where the user input data.

I want when the user press a button get all the texts in the fields in order to check if the data is valid. But i don't know how to get the Text Field in each cell.

Thanks!

Upvotes: 0

Views: 1007

Answers (1)

TomSwift
TomSwift

Reputation: 39502

It's not a good idea to rely on the cell+textfield to be the backing-store for your data. The reason is that the UITableView will recycle those cells as the user scrolls through the list. The only way you can reliably do this is if you allocate/init each cell once and manage them all in an array, from which you retrieve the correct cell when the tableview calls cellForRowAtIndexPath:. But this is a bad idea if you have a lot of rows. If you have only a few rows it can be a fine idea, and then you can simply traverse your array to access each cell/textfield.

Otherwise you need to implement the text field delegate method to capture when the field contents change, in any given cell. When they do, you can grab the field contents and store the value in your backing store. You might consider setting the textField tag to be it's row-index - this is a simple way to know which textField is being updated when your delegate method is called.

Upvotes: 2

Related Questions