Reputation: 7440
I'm making an app that has a view with UITableView
with UISearchDisplayController
. Data comes from NSFetchedResultsController
. All is working fine: I get the data, table view is being populated, search works great. The only problem is that if I search and then click on "Cancel"(without deleting the text from the UISearchBar) and then go back to previous view controller and then go to that same view with UITableView
and UISearchDisplayController
it crashes with this being written to the log:
2012-01-06 16:46:37.559 MyApp[9586:207] *** -[SomeRandomViewController controllerWillChangeContent:]: message sent to deallocated instance 0x778d060
I've googled and stackoverflowed for that error, tried to release NSFetchedResultsController
variable, did set it and its' delegate to nil, but nothing helps.
And if I do some search, then delete the text from the search bar and then tap on "Back" and go back to that view it works just fine.
A bit of the code:
- (void)viewDidUnload {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
self.fetchedResultsController = nil;
self.searchFetchedRC = nil;
[super viewDidUnload];
}
- (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller {
self.fetchedResultsController = nil;
[self fetchedResultsController];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
self.searchDisplayController.searchBar.text = @"";
self.searchDisplayController.active = NO;
[self searchDisplayControllerWillEndSearch:self.searchDisplayController];
return YES;
}
Any help will be appreciated
Update
Without zombies the output to the log is:
2012-01-09 09:25:48.128 Butane[17325:207] -[UITextMagnifierTimeWeightedPoint controllerWillChangeContent:]: unrecognized selector sent to instance 0x8251dc0
Update 2
Dealloc method:
- (void)dealloc {
[self.mySearchDisplayController release];
self.mySearchDisplayController.delegate = nil;
self.mySearchDisplayController = nil;
[self.fetchedResultsController release];
self.fetchedResultsController.delegate = nil;
self.fetchedResultsController = nil;
[self.searchFetchedRC release];
self.searchFetchedRC.delegate = nil;
self.searchFetchedRC = nil;
[self.tableView release];
[textView release];
self.tableView = nil;
self.tableView.delegate = nil;
[super dealloc];
}
mySearchDisplayController = UISearchDisplayController
fetchedResultsController and searchFetchedRC = NSFetchedResultsControllers
tableView = UITableView
textView = [HPGrowingTextView][1]
Update 3
Inspired by the answer of Tia I've set FRCs and their delegates to nil in searchDisplayControllerWillEndSearch
method. Works so far so good
- (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller {
self.fetchedResultsController.delegate = nil;
self.fetchedResultsController = nil;
self.searchFetchedRC.delegate = nil;
self.searchFetchedRC = nil;
[self fetchedResultsController];
}
Upvotes: 0
Views: 1077
Reputation: 1032
I had a similar problem as my VC implemented the UISearchBarDelegate protocol and searchBarTextDidEndEditing: was being called after I'd dismissed the VC in the tableView:didSelectRowAtIndexPath: method.
I fixed it with:
self.searchDisplayController.delegate=nil;
self.searchDisplayController.searchBar.delegate=nil;
before the
[self dismissModalViewControllerAnimated:YES];
Upvotes: 1
Reputation: 9698
- (void)dealloc {
//[self.mySearchDisplayController release];
self.mySearchDisplayController.delegate = nil;
self.mySearchDisplayController = nil;
//[self.fetchedResultsController release];
self.fetchedResultsController.delegate = nil;
self.fetchedResultsController = nil;
//[self.searchFetchedRC release];
self.searchFetchedRC.delegate = nil;
self.searchFetchedRC = nil;
//[self.tableView release];
[textView release];
self.tableView.delegate = nil;
self.tableView = nil;
[super dealloc];
}
You are over-releasing your properties, as setting it to nil
already release it for retained properties. I tried to remove extra releasing code by commenting them out, so please try to replace your dealloc with my code above and see.
Upvotes: 1