有一次这种情况很好,很明显,事情发生了变化。当我离开加载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];
}