I have a UITableViewController which I specified as UISearchBarDelegate. Until now, I programmatically added a UISearchBar to the headerView of the table, and there were no problems.
I ended up shielding the property, so I decided to kill my usual UINavigationController header (which was the text) and added the following code, moving my SearchBar from the table to the UINavigationBar:
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 delegation method:
- (void) searchBarDidBeginEditing:(UISearchBar*) lclSearchBar
{
lclSearchBar.showsCancelButton = YES;
}
... is no longer called. I stopped and I confirmed that the UISearchBar delegate is indeed the view controller itself. Oddly enough, this delegate method is still called just fine:
- (void) searchBarSearchButtonClicked:(UISearchBar *)lclSearchBar
{
_deepSearchRan = NO;
[self runSearchForString:[[self _searchBar] text] isSlowSearch:NO];
[lclSearchBar resignFirstResponder];
}
, UINavigationBar ? ?