0

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?

Brabbeldas
  • 1,939
  • 4
  • 20
  • 32

1 Answers1

0

Try This :-

[yourTextFieldOfCell resignFirstResponder];

before calling [self.tableView reloadData];

funmania
  • 71
  • 2
  • Thanks for your comment. Calling `resignFirstResponder` results in `textFieldDidEndEditing` being called. The result is still the same. I do not want the code in `textFieldDidEndEditing` to be executed. – Brabbeldas Dec 21 '12 at 12:13