EXC BAD ACCESS while using UISearchBar
I think, I need another good advice. Up to now my solution seemed to run well, but now...
OK, the facts:
- I have an ordinary UIViewController
- On top a UINavigationBar, behind that a UISearchBar, hidden initially
- At bottom a UIToolBar
- My main view controller supports UISearchBarDelegate
A switch on UIToolBar toggles the visibility of the UISearchBar
if (show) {
[searchBar setShowsCancelButton:TRUE animated:TRUE];
[navigationBar setHidden:TRUE];
[searchBar becomeFirstResponder];
}
else {开发者_运维技巧
[navigationBar setHidden:FALSE];
[searchBar setShowsCancelButton:FALSE animated:TRUE];
}
searchIsVisible = !searchIsVisible;
There is some animation around, but I have dropped this for example. It works well, I can enter a search string and access it using "searchBarSearchButtonClicked:". I'm also able to react on "searchBarCancelButtonClicked:"
I either didn't notice it before or it happens right now - I'm occasionally catching an EXC BAD ACCESS without further notice. I'm pretty sure, the "[searchBar becomeFirstResponder];" statement is the reason for that, because I can provoke it with tapping into the search line too.
Unfortunately I'm unable to figure out, what the reason is. Do I have to provide another delegate method, as the two I have right now?
Any pointer welcome.
My guess is that searchBar is being deallocated and you don't know it. Probably because your view controller is being deallocated and/or your view hierarchy. Try breaking in your deallocs and seeing whether when they occur makes sense.
精彩评论