在UISearchDisplayController上出现僵尸问题 [英] Having a zombie issue on UISearchDisplayController

查看:91
本文介绍了在UISearchDisplayController上出现僵尸问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将UISearchDisplayController与UITableView一起使用时遇到了僵尸.

I am having a zombie while using a UISearchDisplayController with a UITableView.

UISearchDisplayController(以及视图的其余部分)是通过界面构建​​器(在xcode 5上的故事板,仅使用ARC和iOS 7)设置的.

The UISearchDisplayController (and the rest of the view) is set via interface builder (storyboard on xcode 5 and using ARC and iOS 7 only).

这两种方法都使用searchDisplayController

The searchDisplayController is used by these 2 methods

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
    [self filterContentForSearchText:searchString scope:
     [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
    return YES;
}

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption {
    [self filterContentForSearchText:self.searchDisplayController.searchBar.text scope:
     [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:searchOption]];
    return YES;
}

仪器正在向我提供此信息

Instruments is giving me this information

#   Event Type  ∆ RefCt RefCt   Timestamp   Responsible Library Responsible Caller
0   Malloc  +1  1   00:10.739.188   UIKit   -[UITableView setTableHeaderBackgroundColor:]
1   Retain  +1  2   00:10.739.214   UIKit   -[UIView(Internal) _addSubview:positioned:relativeTo:]
2   Retain  +1  3   00:10.739.234   UIKit   -[UISearchDisplayController _configureSearchBarForTableView]
3   Retain  +1  4   00:10.739.291   UIKit   -[UIView(Hierarchy) subviews]
4   Retain  +1  5   00:10.771.238   UIKit   -[UIView(Hierarchy) subviews]
5   Retain  +1  6   00:10.782.890   QuartzCore  -[CALayer layoutSublayers]
6   Release -1  5   00:10.782.891   QuartzCore  -[CALayer layoutSublayers]
7   Release -1  4   00:10.792.538   QuartzCore  CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*)
8   Release -1  3   00:15.446.447   UIKit   -[UITableView dealloc]
9   Release -1  2   00:15.446.661   UIKit   -[UIView(Internal) _invalidateSubviewCache]
10  Release -1  1   00:15.446.679   UIKit   -[UIView(Hierarchy) removeFromSuperview]
11  Release -1  0   00:15.446.744   UIKit   -[UITableView setTableHeaderBackgroundColor:]
12  Zombie      -1  00:15.446.765   UIKit   -[UISearchDisplayController _cleanUpSearchBar]

我试图用这样的dealloc方法清理UISearchDisplayController

I tried to clean up the UISearchDisplayController in the dealloc method like this

-(void)dealloc {
    self.searchDisplayController.searchResultsTableView.delegate = nil;
    self.searchDisplayController.delegate = nil;
    self.searchDisplayController.searchBar.delegate = nil;
    self.searchDisplayController.searchResultsDelegate = nil;
    self.searchDisplayController.searchResultsDataSource = nil;
}

但是没有用.

您知道我在做什么错吗?

Have you any idea of what I am doing wrong ?

感谢您的帮助.

推荐答案

我认为我已经能够解决此问题.这是有关变通办法的另一个问题:

I think I've been able to work around this problem. Here's another question talks about workarounds:

UISearchDisplayController在viewDidUnload之后导致崩溃

所以我添加了:

@property (nonatomic, weak) IBOutlet UISearchBar *searchBar;
@property (nonatomic) UISearchDisplayController *searchController;

然后在viewDidLoad中:

And then in viewDidLoad:

UISearchDisplayController *searchController = [[UISearchDisplayController alloc] initWithSearchBar:[self searchBar] contentsController:self];
[searchController setDelegate:self];
[searchController setSearchResultsDelegate:self];
[searchController setSearchResultsDataSource:self];
[self setSearchController:searchController];

然后在dealloc中:

And in dealloc:

[self setSearchController:nil];

这似乎已经解决了.

这篇关于在UISearchDisplayController上出现僵尸问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆