2

I get this error ("ViewController respondsToSelector:]: message sent to deallocated instance") when I enable "Zombie Objects". I found where is error but I don't know how to solve it.

Here is code: ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UISearchDisplayDelegate, UISearchBarDelegate>{


    // The saved state of the search UI if a memory warning removed the view.
    NSString        *savedSearchTerm;
    NSInteger       savedScopeButtonIndex;
    BOOL            searchWasActive;
}

@property (nonatomic, copy) NSString *savedSearchTerm;
@property (nonatomic) NSInteger savedScopeButtonIndex;
@property (nonatomic) BOOL searchWasActive;

ViewController.m

...
// when I comment out "viewDidDisappear" everything is ok, how to solve this on different way?
- (void)viewDidDisappear:(BOOL)animated
{
    // save the state of the search UI so that it can be restored if the view is re-created
    self.searchWasActive = [self.searchDisplayController isActive];
    self.savedSearchTerm = [self.searchDisplayController.searchBar text];
    self.savedScopeButtonIndex = [self.searchDisplayController.searchBar selectedScopeButtonIndex];
}...

Thank's for help

iWizard
  • 6,816
  • 19
  • 67
  • 103

3 Answers3

2

What are you doing to "create" this error ?

I my case, I popped the ViewController off the navigation stack and there were still NSNotifications sent to this VC. I simply forgot to remove all observers to my VC.

matthisb
  • 1,108
  • 12
  • 29
0

You should put [super viewDidDisappear:animated] at the beginning of your override, as that is the default implementation. Forgetting that line can sometimes cause problems.

edit:

I think you might need to post some more code. The key might be in something else you're doing or not doing.

Dima
  • 23,484
  • 6
  • 56
  • 83
0
/*
- (void)viewDidDisappear:(BOOL)animated
{
    // save the state of the search UI so that it can be restored if the view is re-created
    self.searchWasActive = [self.searchDisplayController isActive];
    self.savedSearchTerm = [self.searchDisplayController.searchBar text];
    self.savedScopeButtonIndex = [self.searchDisplayController.searchBar selectedScopeButtonIndex];
}
*/
iWizard
  • 6,816
  • 19
  • 67
  • 103