iOS ARC(?) steals my searchbar

141 views Asked by At

I've made a iOS5-app quite similar to Apple's Contacts-app. A searchbar, a serachdisplaycontroller a tableview. When the user tap a cell a detailed view is presented (modal-style...) using segues. Everything works well, but... I've seen my app crash on the real iPhone 4S device when the app has been sleeping in the background for several hours and then get active again. The crash is impossible to re-create under ordered circumstances. Ok, some kind of memory issue...

On the iOS-simulator I can see the crash if

-> A cell is tapped (or a button for the settings-view) -> The detailed view is presented (or the settings-view is presented) -> A "Simulate Memory Warning" is issued -> The user try to navigate back using a "Done"-button.

- (IBAction)done:(id)sender
{
    [self.delegate detailedViewControllerDidFinish:self];
}

- (void)detailedViewControllerDidFinish:(DetailedViewController *)controller
{    
    [self dismissModalViewControllerAnimated:YES];
}

2012-01-17 19:58:43.777 MyApp[89968:f803] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key searchBar.' * First throw call stack:...

So for some reason the serachbardisplaycontrol get invalid (I guess) when the OS want some of my app's memory back

Any ideas?

1

There are 1 answers

0
salil On

I think I have successfully solved this one. It comes down to the search bar being active when a low-memory condition is triggered. When you hit a low-memory condition, do this:

[self.searchDisplayController setActive:NO animated:NO];

That should fix it.