2
有一次,这工作得很好,很明显,事情已经改变。当我离开装载searchDisplayController的viewController时,我的应用程序正在向已释放的实例发送消息。堆栈是为什么我相信这是searchDisplayController: 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];
}
我知道你说你已经找到了解决办法,但你的例子还缺少一两件事情:你的'viewDidUnload'和'viewDidDisappear:'应该调用'[超级viewDidUnload]'和' [super viewDidDisappear:animated];'分别在每个末尾。 –
谢谢!我很欣赏这些意见。 – Selch