Note that there are some explanatory texts on larger screens.

plurals
  1. POUISearchBar cancel button crash
    text
    copied!<p>I have a UITableView that on didSelectRowAtIndexPath pushes another UITableView to do a search...</p> <pre><code> LocationSearchViewController *locationSearchViewController = [[LocationSearchViewController alloc] initWithNibName:@"LocationSearchViewController" bundle:nil]; locationSearchViewController.delegate = self; UITableViewCell *cell = [myTableView cellForRowAtIndexPath:indexPath]; locationSearchViewController.defaultLocation = cell.detailTextLabel.text; [[self navigationController] pushViewController:locationSearchViewController animated:YES]; [locationSearchViewController release]; </code></pre> <p>The search view contains a UISearchBar with it's cancel button enabled. If the user taps the cancel button the app crashes with an objc_exception_throw. The console displays...</p> <blockquote> <p>2011-02-06 22:05:43.960 JetLogger[2381:207] <em>*</em> Assertion failure in -[UISearchDisplayController setActive:animated:], /SourceCache/UIKit_Sim/UIKit-1447.6.4/UISearchDisplayController.m:589</p> </blockquote> <p>If, however, the user taps an item in the table view (search results) I am closing the search view and there is no crash. I can't see why the difference as I am popping the search view with the same code...</p> <p>In the LocationSearchViewController...</p> <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if ([self.delegate respondsToSelector:@selector(locationSearchViewDidDismiss:withLocation:)]) { [self.delegate locationSearchViewDidDismiss:self withLocation:[tableView cellForRowAtIndexPath:indexPath].textLabel.text]; } } - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{ if ([self.delegate respondsToSelector:@selector(locationSearchViewDidDismiss:withLocation:)]) { [self.delegate locationSearchViewDidDismiss:self withLocation:@"No results found"]; } } </code></pre> <p>In the delegate...</p> <pre><code>- (void)locationSearchViewDidDismiss:(LocationSearchViewController *)controller withLocation:(NSString*)location{ if((location != @"") &amp;&amp; (location != @"No results found")){ //update the table data [myTableView reloadData]; } [self.navigationController popViewControllerAnimated:YES]; } </code></pre> <p>Any help is appreciated.</p> <p>John </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