2012-11-30 64 views
2

有一次,這工作得很好,很明顯,事情已經改變。當我離開裝載searchDisplayController的viewController時,我的應用程序正在向已釋放的實例發送消息。堆棧是爲什麼我相信這是searchDisplayController: enter image description heresearchDisplayController被釋放,崩潰

看着我的代碼,我不知道它在哪裏得到釋放。我會很感激任何想法。謝謝。

編輯: 我應該補充說,如果我註釋掉我的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]; 
} 
+1

我知道你說你已經找到了解決辦法,但你的例子還缺少一兩件事情:你的'viewDidUnload'和'viewDidDisappear:'應該調用'[超級viewDidUnload]'和' [super viewDidDisappear:animated];'分別在每個末尾。 –

+0

謝謝!我很欣賞這些意見。 – Selch

回答

相關問題