在有关 searchDisplayController
属性的 UIViewController
documentation 中1,它说:
如果您以编程方式创建搜索显示控制器,则在其初始化时,此属性会由搜索显示控制器自动设置。
当我这样创建我的 UISearchDisplayController
时:
[[[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self] autorelease];
-[UIViewController searchDisplayController]
不是 nil
。但是,在事件循环完成后,它会被置为 nil,这导致当我点击搜索栏内部时,搜索显示控制器不会显示。没有任何崩溃。这非常奇怪。如果我省略对 autorelease
的调用,一切都正常:
[[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
然而,发生了泄漏
UISearchDisplayController
(我通过Instruments进行了验证)。由于searchDisplayController
property被标记为(nonatomic, retain, readonly)
,我期望它在设置后会保留UISearchDisplayController
。
这篇stackoverflow文章与此有关。