6

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??

M Penades
  • 1,572
  • 13
  • 24
  • Can you post your codes? – Raptor Nov 04 '11 at 09:58
  • I am having the opposite behaviour on my searchBar. I get searchBarTextDidBeginEditing but not searchBarShouldBeginEditing... Maybe Apple messed up something in the latest SDK? What SDK are you using? – Mark May 24 '13 at 18:02
  • I m sorry, but I have not anymore the code... I think that I solved it recreating the whole project (and still do not know what was failling in that first one.) – M Penades Jun 03 '13 at 14:51

3 Answers3

13

did you set the delegate property?

searchbar.delegate = self;
defvol
  • 14,392
  • 2
  • 22
  • 32
  • 1
    I did both ways through interface builder, and throught code (and both at same time XD ) Anyway I dont think this is the problem as one of delegate function do get called (searchBarShouldBeginEditing). Thanks for the answer by the way! – M Penades Nov 04 '11 at 10:17
1

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

Oleg Kovtun
  • 362
  • 1
  • 3
0

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!

Snips
  • 6,575
  • 7
  • 40
  • 64