I have a UITableViewController that I have specified as a UISearchBarDelegate. Up until now, I had programmatically added the UISearchBar to the headerView of the table, and there were no problems.
I began to run out of screen real estate, so I decided to kill my normal UINavigationController title (which was text), and added the following code, moving my SearchBar from the table to the UINavigationBar:
// (Called in viewDidLoad)
// Programmatically make UISearchBar
UISearchBar *tmpSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0,0,320,45)];
tmpSearchBar.delegate = self;
tmpSearchBar.showsCancelButton = YES;
tmpSearchBar.autocorrectionType = UITextAutocorrectionTypeNo;
tmpSearchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;
[self set_searchBar:tmpSearchBar];
[tmpSearchBar release];
self.navigationItem.titleView = [self _searchBar];
This code works as expected - my UINavigationBar is now a UISearchBar. However, my delegate method:
/** Only show the cancel button when the keyboard is displayed */
- (void) searchBarDidBeginEditing:(UISearchBar*) lclSearchBar
{
lclSearchBar.showsCancelButton = YES;
}
...is no longer being called. I've breakpointed, and I've confirmed that the UISearchBar's delegate is indeed self, the view controller. Oddly, this delegate method is still called just fine:
/** Run the search and resign the keyboard */
- (void) searchBarSearchButtonClicked:(UISearchBar *)lclSearchBar
{
_deepSearchRan = NO;
[self runSearchForString:[[self _searchBar] text] isSlowSearch:NO];
[lclSearchBar resignFirstResponder];
}
Any ideas why UINavigationBar is swallowing my delegate calls?? What am I missing?