Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

resignFirstResponder causing EXC_BAD_ACCESS

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?

like image 943
kolinko Avatar asked Nov 05 '22 09:11

kolinko


1 Answers

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.

like image 102
MikeyWard Avatar answered Nov 09 '22 15:11

MikeyWard