iphone - ViewController 响应选择器 :]: message sent to deallocated instance

标签 iphone objective-c xcode

当我启用“僵尸对象”时,我收到此错误(“ViewController respondsToSelector:]: message sent to deallocated instance”)。我找到了错误所在,但不知道如何解决。

这是代码: 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];
}...

感谢您的帮助

最佳答案

您正在做什么来“创建”此错误?

就我而言,我将 ViewController 从导航堆栈中弹出,并且仍然有 NSNotifications 发送到该 VC。我只是忘记删除我的 VC 的所有观察者。

关于iphone - ViewController 响应选择器 :]: message sent to deallocated instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10537147/

相关文章:

ios - 在编写重复代码时如何节省时间?

iphone - iOS:在 [NSUserDefaults standardUserDefaults] 中存储敏感的用户信息是否安全?

iphone - ios asihttprequest 发布字符串

ios - 是否有用于在 iPhone 应用程序中设置首选项的库或框架?

iphone - 如何根据 objective-c 中的月份创建周列表?

objective-c - 文件属性是否包含毫秒? Objective-C

iphone - 可以在 iOS 6 中显示 "in App Store modal"吗?

ios - 创建类的实例返回警告?

ios - 文件 “MyProgramm.ipa” 无法打开,因为没有该文件

ios - 父 View 中的 Swift 容器控件