当我启用“Zombie Objects”时,我收到此错误(“ViewController respondsToSelector:]:发送到解除分配的实例的消息”)。我发现错误在哪里,但我不知道如何解决它。
这是代码: 的 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];
}...
感谢您的帮助
答案 0 :(得分:2)
你在做什么来“创造”这个错误?
我的情况是,我将ViewController从导航堆栈中弹出,并且仍然有NSNotifications发送到此VC。我只是忘了删除所有VC的观察者。
答案 1 :(得分:0)
您应该在覆盖的开头放置[super viewDidDisappear:animated],因为这是默认实现。忘记这一行有时会导致问题。
编辑:
我认为您可能需要发布更多代码。关键可能在于你正在做或不做的其他事情。
答案 2 :(得分: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];
}
*/