views:

197

answers:

3

Hi, I think, I need another good advice. Up to now my solution seemed to run well, but now...

OK, the facts:

  1. I have an ordinary UIViewController
  2. On top a UINavigationBar, behind that a UISearchBar, hidden initially
  3. At bottom a UIToolBar
  4. 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. Regards

A: 

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.

Steve Weller
A: 

Hmm. Thanks. The searchBar is a property (nonatomic, retain). Is is deallocated in this supposed to be deallocated? Would you mind to be a bit more specific in what you mean by "try breaking in your deallocs"?

Two things are strange: 1) It doesn't happen on the device... 2) It is really just the "becomeFirstResponder", which crashes. The "showCancelButton" doesn't harm.

neil
A: 

Sorry, I was sending in the middle of a sentence: Read: "Is is deallocated in this supposed to be deallocated? " As: "It is deallocated in 'dealloc' and set to 'nil' in 'viewDidUnload'"

Kind regards

neil