LettersBa
LettersBa

Reputation: 767

TextField return null when the cell is scrolled out of window

I have a UITableViewCell with 10 rows, inside they I have UITextFields.

When I try to get the value inside the textfield my code returns that value, but when I scroll down my table (put my textfield out of window) and I try to get the value inside him my code returns null!

NSIndexPath *myIP = [NSIndexPath indexPathForRow:1 inSection:0];
        ProfileTableViewCell *cell = [tableView cellForRowAtIndexPath:myIP];
        UITextView *text1 = (UITextView *)[cell.contentView viewWithTag:1];
        UITextView *text2 = (UITextView *)[cell.contentView viewWithTag:2];

Why this is happening? Because when the cell is scrolled out of window, the textfield may be released

And what I can do to solve this problem? Save the input in somewhere and read from there in cell construction method

Well I get this answers reading this solution, now 4 years ago is passed, I believe that have a more modern solution to solve this problem, right?

Upvotes: 1

Views: 49

Answers (1)

stonesam92
stonesam92

Reputation: 4457

From the docs, UITableView provides "a means for displaying and editing hierarchical lists of information."

It is not meant to act as a store for any data, it merely provides the user a way to interact with it.

As per the answer you linked to, you will have to store this data elsewhere if you want it to persist after the cell has been reused or released.

Upvotes: 3

Related Questions