2

This project is for iPhone with iOS 5 using ARC and Core Data.

All built in Xcode Storyboards, I have a UITabBarController with a few tabs. Three of these views are UITableViewControllers with a UISearchDisplayController attached. If I simulate a memory warning in the iPhone simulator, whatever views are not active get dumped, and when I tap on the tab for one of these views with the searchDisplayController, NSZombieEnabled tells me -[UISearchDisplayController retain]: message sent to deallocated instance.

Here's my -didReceiveMemoryWarning:

- (void)didReceiveMemoryWarning
{
    [(PahAppDelegate *)[[UIApplication sharedApplication] delegate] saveContext];
    // Release any cached data, images, etc that aren't in use.
    self.searchWasActive = [self.searchDisplayController isActive];
    self.savedSearchTerm = [self.searchDisplayController.searchBar text];
    self.savedScopeButtonIndex = [self.searchDisplayController.searchBar selectedScopeButtonIndex];

    self.fetchedResultsController.delegate = nil;
    self.fetchedResultsController = nil;
    self.searchFetchedResultsController.delegate = nil;
    self.searchFetchedResultsController = nil;

    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
}

My best guess is that the UITableViewController dumps the subviews as well, and for whatever reason, it's not re-creating them when I go back to the other tabs. Since all of that functionality is built in Storyboard, I'm not quite sure how to go about requesting it re-load the searchDisplayController in question.

Note: I've never seen the app do this in the real world on the device (and neither have my beta testers), but I don't want Apple to refuse approval of the app because of this; plus fixing it seems like The Right Thing to Do.

searchDisplayController is a readonly property, so I'm not sure what tack to take to get things loaded like they should be.

John Topley
  • 113,588
  • 46
  • 195
  • 237
swizzlevixen
  • 325
  • 1
  • 12
  • Seems as if it may be a bug in Storyboard. Worked around for now by creating the `UISearchDisplayController` in code, as Brian Cooke suggests below. – swizzlevixen Mar 06 '12 at 21:25

1 Answers1

1

This definitely seems like a, possibly Storyboards, bug. As mentioned here: UISearchDisplayController causes crash after viewDidUnload, a brand new project using Storyboards and a UISearchDisplayController can reproduce this without even connecting an outlet for the UISearchDisplayController into your controller. The suggestion in that thread seems sane, create the UISearchDisplayController in code. I can't vouch for the workaround as I didn't test it, but I was curious and did reproduce the new project = crash claim and saw the exact same thing.

Community
  • 1
  • 1
  • I am coming to the same conclusion. I built a sample test project myself, just laying it out in Storyboard and not adding any custom code, and it still reproduces. – swizzlevixen Mar 06 '12 at 20:41
  • I add my answer to the other thread Brain mentioned. please see http://stackoverflow.com/questions/8567525/uisearchdisplaycontroller-causes-crash-after-viewdidunload/10734813#10734813 – Wayne Liu May 24 '12 at 09:36