2

ある時点でこれは正常に機能していましたが、明らかに何かが変わっています。searchDisplayController をロードする viewController を離れると、アプリは割り当てが解除されたインスタンスにメッセージを送信しています。スタックは、それがsearchDisplayControllerであると私が信じる理由です: ここに画像の説明を入力

私のコードを見てみると、どこで割り当てが解除されるのかわかりません。アイデアをいただければ幸いです。ありがとう。

編集: viewDidDisappear メソッドをコメントアウトすると、クラッシュが停止することを追加する必要があります。

-(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];
}

関連するビットは次のとおりです。

@interface ShowAttributesViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, UISearchDisplayDelegate, UISearchBarDelegate>
{   
    IBOutlet UITableView *attributesTableView;
    NSString        *savedSearchTerm;
    NSInteger   savedScopeButtonIndex;
    BOOL            searchWasActive;   
}   
@property (nonatomic, retain) UITableView *attributesTableView;
@property (nonatomic, retain) NSMutableArray *filteredattributesArray;
@property (nonatomic, copy) NSString *savedSearchTerm;
@property (nonatomic) NSInteger savedScopeButtonIndex;
@property (nonatomic) BOOL searchWasActive;



- (void)viewDidLoad
{
    [super viewDidLoad];

    self.filteredattributesArray = [NSMutableArray arrayWithCapacity:[[[SharedAppData sharedStore] attributesArray] count]];

    if (self.savedSearchTerm)
    {
        [self.searchDisplayController setActive:self.searchWasActive];
        [self.searchDisplayController.searchBar setSelectedScopeButtonIndex:self.savedScopeButtonIndex];
        [self.searchDisplayController.searchBar setText:savedSearchTerm];

        self.savedSearchTerm = nil;
    }
}

-(void)viewDidDisappear:(BOOL)animated {
    self.searchWasActive = [self.searchDisplayController isActive];
    self.savedSearchTerm = [self.searchDisplayController.searchBar text];
    self.savedScopeButtonIndex = [self.searchDisplayController.searchBar selectedScopeButtonIndex];
}

-(void)viewDidUnload {

    self.filteredattributesArray = nil;
}

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
    [self filterContentForSearchText:searchString];
    return YES;
}

- (void)searchDisplayController:(UISearchDisplayController *)controller willUnloadSearchResultsTableView:(UITableView *)tableView {

    [attributesTableView reloadData];
}
4

1 に答える 1

0

他の人と同じように、たくさん掘り下げた後、問題を解決するこの投稿を見つけました。

UISearchDisplayController 自動解放クラッシュ

于 2012-11-30T19:43:12.427 に答える