在某一时刻,这工作得很好,显然,有些事情发生了变化。当我离开加载 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];
}