【发布时间】:2016-09-22 00:22:30
【问题描述】:
我在构建使用UISearchController 的基本用户界面时遇到了这个问题,它是UISearchBar 成员。我的 tableView 是一个弱 IBOutlet,就像 Apple Docs 演示的那样,我将它的 tableHeaderView 属性设置为搜索栏成员。
//Snippet from viewDidLoad
UISearchController* searchController = [self createSearchController];
UISearchBar* searchBar = searchController.searchBar;
searchBar.userInteractionEnabled = NO;
self.tableView.tableHeaderView = searchBar; //The assignment in question
[NetworkStuff makeCall:^(Response *response) {
//handle success
searchBar.userInteractionEnabled = YES; //local variables
searchController.active = YES;
...
} failure:^(Response *response) {
//handle failure
...
}];
当我从堆栈中弹出视图时,它的 dealloc 方法永远不会被调用,即使我在viewWillDisappear: 中将 tableHeaderView 设置为 nil。我需要注释掉才能看到调用 dealloc 的唯一行是初始分配。
有人知道为什么会发生这种情况吗?
编辑:
发现了一些有趣的行为。同样根据 Apple Docs,我将控制器的 definesPresentationContext 变量设置为 YES。在将 tableViewHeader 分配保留在固定保留周期中时将其注释掉,即使我没有取消 tableViewHeader。但是,在viewDidLoad 中设置definesPresentationContext 并在viewWillDisappear 中清除它会重新引入保留周期。
【问题讨论】:
标签: ios objective-c uitableview automatic-ref-counting uisearchbar