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