开发者

Custom tableViewCell resignFirstResponder when scrolled offscreen

I have a table that contains multiple cu开发者_如何学Cstom 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜