views:

73

answers:

1

Hi there,

I've got a UISearchBar on my UITableView and a method -finishSearching which looks like this:

- (void)finishSearching {
    [overlayViewController.view removeFromSuperview];
    if ([sb isFirstResponder])
        [sb resignFirstResponder];
    myTableView.scrollEnabled = YES;
}

This method gets called everytime I want to stop searching. Be it using the cancel or the search button or just tapping on the UITableView. The problem is that I always get an EXC_BAD_ACCESS when it comes to [sb resignFirstResponder]; and I have no idea why. My goal is to implement a behavior like in Address Book where you can tap the searchBar which makes it stick to the top and put that grey overlay over the UITableView.

Any suggestions on that one?

Best
–f

+2  A: 

Are you sure that by removeFromSuperview the sb will not be released a little too early? Try resigning first and then removing the view from the superview.

mvds
Uhm, I'm not removing `sb` from it's superview here. It's the `overlayViewController`'s view property.
flohei
I know. But I wonder who is retaining the `sb`. If you're positive that your object is retaining it, look for another solution.
mvds
Ok, I found the bug. I was producing an infinite loop when resigning first responder because I called my `-finishSearching` method from within the method that gets called when the `searchBar` wants to resign the `firstResponder` status. Thanks anyways!
flohei