2012-05-10 15 views
2

当我启用“僵尸对象”时,出现此错误(“ViewController respondsToSelector:”:发送到释放实例的消息)。我发现错误在哪里,但我不知道如何解决它。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

你曾经解决过这个问题吗?我有同样的问题。 – achi

+0

@EliGregory - 是的。我评论viewDidDisappear :) – CroiOS

+2

所以我没有重写该方法,生病得看看别处 – achi

回答

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]; 
} 
*/ 
0

你应该把[超级viewDidDisappear:动画]在重写的开始,因为这是默认的实现离子。忘记这条线有时会导致问题。

编辑:

我想你可能需要发布一些更多的代码。关键可能在于你正在做或未做的其他事情。

+0

谢谢,但这不是问题。 – CroiOS

2

你在做什么来“创造”这个错误?

我的情况是,我将ViewController弹出导航堆栈,并且仍然有NSNotifications发送给此VC。我只是忘了将所有观察员都移除到我的VC。

相关问题