Brabbeldas
Brabbeldas

Reputation: 1949

UITableView inform UITableViewCell about reload

Here is a short summary of the situation:

I have a TableViewController with a number of cells. In one of the cells I have a UITextField. This cell is of a custom UITableViewCell class. This class implements the UITextFieldDelegate protocol and the method textFieldDidEndEditing: Within the method textFieldDidEndEditing: I store the value of the TextField into CoreData.

This all works great.

My question relates to reloading the TableView:

After certain actions of the user I reload the data of the UITableView by calling [self.tableView reloadData] If, when I call this method, the above mentioned TextField is first responder, the textFieldDidEndEditing: method will be called, causing my CoreData related code to execute.

When the TableView is being reloaded I do not want the custom TabelViewCell to do anything at all. Is there a way, the TableViewCell can be aware of the TableView being reloaded? So I can check for this within the textFieldDidEndEditing: method?

In the meantime I have solved it in the following way:

When this TableViewCell is being created I let the ViewController store a reference to it. Before calling [self.tableView reloadData] I first inform the Cell by setting a custom property _cell.tableWillReload = YES I will check for this property within the textFieldDidEndEditing: method.

I was thinking maybe there is a different, more default way, for TableViewCells to know they surroundingTableView is reloading?

Upvotes: 0

Views: 182

Answers (1)

funmania
funmania

Reputation: 71

Try This :-

[yourTextFieldOfCell resignFirstResponder];

before calling [self.tableView reloadData];

Upvotes: 0

Related Questions