Note that there are some explanatory texts on larger screens.

plurals
  1. POUISearchBar delegate not called when used as UINavigationBar titleVIew?
    text
    copied!<p>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.</p> <p>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:</p> <pre><code>// (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]; </code></pre> <p>This code works as expected - my UINavigationBar is now a UISearchBar. However, my delegate method:</p> <pre><code>/** Only show the cancel button when the keyboard is displayed */ - (void) searchBarDidBeginEditing:(UISearchBar*) lclSearchBar { lclSearchBar.showsCancelButton = YES; } </code></pre> <p>...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:</p> <pre><code>/** Run the search and resign the keyboard */ - (void) searchBarSearchButtonClicked:(UISearchBar *)lclSearchBar { _deepSearchRan = NO; [self runSearchForString:[[self _searchBar] text] isSlowSearch:NO]; [lclSearchBar resignFirstResponder]; } </code></pre> <p>Any ideas why UINavigationBar is swallowing my delegate calls?? What am I missing?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload