Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Use the following two methods in the <code>UISearchBarDelegate</code> and do something like this:</p> <pre><code>- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar { [searchBar setShowsCancelButton:YES animated:YES]; } - (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar { [searchBar setShowsCancelButton:NO animated:YES]; } </code></pre> <p>If you want the search to appear more responsive you can move your posted code to the <code>searchBar:textDidChange:</code> delegate method and then only use <code>searchBarSearchButtonClicked:</code> to do a <code>[searchBar resignFirstResponder]</code>:</p> <pre><code>- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { [searchBar resignFirstResponder]; } - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { _fetchedResultsController = nil; NSError *error; if (![[self fetchedResultsController] performFetch:&amp;error]) { NSLog(@"Error in search %@, %@", error, [error userInfo]); } else { [self.timelineTableView reloadData]; [self.noResultsLabel setHidden:_fetchedResultsController.fetchedObjects.count &gt; 0]; } } </code></pre> <p>Additionally you can use the <code>searchBarCancelButtonClicked:</code> to also resign the first responder from the search bar and then update your table view by calling the delegate <code>searchBar:textDidChange:</code>:</p> <pre><code>- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar { [searchBar setText:@""]; [self searchBar:searchBar textDidChange:@""]; [searchBar resignFirstResponder]; } </code></pre>
 

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