[英]searchDisplayController being deallocated, crashing
At one point this was working fine and, obviously, something has changed. 一方面,它运行良好,并且显然已经发生了变化。 When I leave the viewController that loads the searchDisplayController my app is sending a message to a deallocated instance.
当我离开加载searchSearchController的viewController时,我的应用程序正在向已释放的实例发送消息。 The stack is why I believe it's the searchDisplayController:
堆栈是为什么我相信它是searchDisplayController的原因:
Looking over my code, I'm not sure where it gets deallocated. 查看我的代码,我不确定它在哪里释放。 I'd appreciate any ideas.
我将不胜感激。 Thanks.
谢谢。
EDIT: I should add that if I comment out my viewDidDisappear method, the crashes stop. 编辑:我应该补充一点,如果我注释掉我的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];
}
Here are the relevant bits: 以下是相关的位:
@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];
}
After a lot of digging, like others, I found this post that resolves the issue. 经过与其他人的大量挖掘,我找到了解决此问题的帖子。
UISearchDisplayController autorelease crash UISearchDisplayController自动释放崩溃
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.