views:

62

answers:

1

Hi, I've got a UITextField on UITableViewCell, and a button on another cell.

I click on UITextField (keyboard appears).

UITextField has the following method called:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
        NSLog(@"yes, it's being called");
 owner.activeTextField = textField;
 return YES;
};

Where owner.activeTextField is a (retain, nonatomic) property.

The problem When the keyboard is visible I scroll the cell out of the view. I then click a button that is on a different cell. The button calls:

[owner.activeTextField resignFirstResponder]

And that causes EXC_BAD_ACCESS.

Any idea? The cell is most definitely in the memory. My guess is that once it disappears it is removed from the view and one of it's properties (parent view?) becomes nil and that causes the said error..

Am I right?

TL;DR; How can I remove the keyboard (resign first responder) when UITextField is removed from the view?

+1  A: 

Sometimes the problem can be another level deep... Check and make sure that the next object in the responder chain (the one that's subsequently receiving the becomeFirstResponder message) isn't garbage. Just a thought.

MikeyWard
Good idea.. i checked the nextResponder property of the textField (and the 3 next nextResponders), but they seem fine (redirect to existing objects), so I guess that's not it.
Merlin