2

「Zombie Objects」を有効にすると、このエラー (「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];
}...

手伝ってくれてありがとう

4

3 に答える 3

0

[super viewDidDisappear:animated] をオーバーライドの先頭に配置する必要があります。これがデフォルトの実装です。その行を忘れると、問題が発生することがあります。

編集:

もう少しコードを投稿する必要があるかもしれないと思います。鍵は、あなたがしている、またはしていない他の何かにあるかもしれません。

于 2012-05-10T16:07:17.957 に答える
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];
}
*/
于 2013-03-14T09:46:39.680 に答える