UISearch bar not calling searchBarTextDidBeginEditing

9.5k views Asked by At

I have a simple view controller with a uisearchbar and a uitable. My problem is that when search bar is tapped I see delegate function searchBarShouldBeginEditing being called but not searchBarTextDidBeginEditing(and because of that keyboard is not opened and search is not editable)

I tried to implement delegate function searchBarShouldBeginEditing returning YES, set searchbar as first responder, but no way I get searchBarTextDidBeginEditing called...

Any idea what could be happening??

Some code:

controller.h

@interface ViewController : UIViewController <UISearchBarDelegate>
{
   UISearchBar * searchbar;
}

@property (nonatomic, retain) IBOutlet UISearchBar* searchbar;

@end

controller.m

@synthesize searchbar;

- (BOOL)respondsToSelector:(SEL)sel {
    NSLog(@"Queried about %@", NSStringFromSelector(sel));
    return [super respondsToSelector:sel];
}

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
    NSLog(@"searchBarShouldBeginEditing -Are we getting here??"); 
    return YES;  
}  
-(void) searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
    NSLog(@"searchBarTextDidBeginEditing -Are we getting here??");  
}

Of cousrse my class have plenty more code (that surely is affecting somehow searchbar) but if someone has got similar problems with searchbar it would be very apreciated its response ;)

I tryed to make simple application with only searchbar and obviously it works...

EDITING:

Testing a little bit I discovered that it is not something related with uisearchbar as I added a TextField getting same result (just textFieldShouldStartEditing delegate function being called)

Application has all view controllers inside a UITabBar cotroller, but I do not think this can cause all this mess...

EDITING2:

Really strange behaviour: Setting IBAction function to TouchDown event of a UITextfield works perfectly but setting IBAction function to EditingDidBegin never gets fired...

Why this event could not be called??

3

There are 3 answers

1
defvol On

did you set the delegate property?

searchbar.delegate = self;
0
Snips On

I had this problem when I was converting from a standalone UISearchBar to a searchBar integrated into the UINavigationBar.

In converting my code, I was still allocating the UISearchBar and setting the delegate for that. What I should have been doing was configuring the searchBar that comes as part of of the UISearchController, and setting the delegate of that,

self.searchController.searchBar.delegate = self;

Once I did that, my delegate methods started firing!

0
Oleg Kovtun On

Maybe you somewhere call [searchbar resignFirstResponder]. It was the case in my similar problem.