0

I have a table that contains multiple custom tableViewCells each of which contains a textField. What I have discovered is that if I enter text into one text field, and (without pressing the done button on the keyboard) scroll the text field off screen to enter text into another cell, the app crashes when the view is changed. This occurs most frequently in landscape mode since the current tableViewCell needs to be scrolled offscreen to generate the error on view change.

What I believe is happening is that when the cell goes off screen, the connection between the cell and the keyboard is broken and that when the view is changed, removing they keyboard for a non visible (non existent) text field causes the crash.

I am sure this is a simple fix, but I haven't found it yet.

Thanks in advance.

  • Found the solution here: http://stackoverflow.com/questions/5000785/resignfirstresponder-to-uitextviews-on-uitableviewcells-that-are-no-longer-on-scr I needed to set the identifier on the .xib as well as in the .m file – ShouldBeWriting Jun 29 '11 at 14:16
  • You need evidence. To collect it, try debugging and paste the crash log along with your question. – ZhangChn Jun 29 '11 at 14:16

1 Answers1

0

You can try something like this:

CustomUITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Gioni"];

// If no cell is available, create a new one using the given identifier.
if (cell == nil) {
    cell = [[[CustomUITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Gioni"] autorelease];
}
else
{
     [cell resignFirstResponderForObjectInCell];
}

This way you will know when your cell (the one with your special identifier) is going to be reused... so it means it's off the screen. You can make it resign first responder status before remaking another one like it.

Fervus
  • 710
  • 7
  • 18