ios 7中的新UISearhBar

arc*_*ger 4 xcode cocoa-touch objective-c uisearchbar ios7

嗨,大家好.

我在iOS 7中使用新的uisearchbar时遇到了一些麻烦

在我的应用程序中,在tableHeaderView中有一个带有搜索栏的tableview它是手工制作的(以编程方式添加) - 在storyboard中的tableviewcontroller,在方法viewDidLoad中我添加了searchDisplayController,我的自定义搜索栏继承自UISearchBar.

所有事情都在导航控制器中.

我的应用程序的逻辑在某些方面我发布这个导航控制器发送dismissViewController

在ios 6中它完美无缺.

但在ios 7中,我在尝试发布导航控制器时遇到了崩溃.

在日志我有趣的线...

到viewDidLoad的末尾我添加这个:

for (UIView *view in self.view.subviews) {
    NSLog(@"%@ %p", [view.class description], view);
}
Run Code Online (Sandbox Code Playgroud)

在ios 6我只有这个

2013-09-19 12:40:40.553 myApp[4182:c07] KRSearchBar 0x988bdd0
Run Code Online (Sandbox Code Playgroud)

在ios 7中:

2013-09-19 13:08:47.808 myApp[4690:a0b] UIView 0xa265310
2013-09-19 13:08:47.809 myApp[4690:a0b] UITableViewWrapperView 0xa25b4d0
2013-09-19 13:08:47.810 myApp[4690:a0b] KRSearchBar 0xa2591b0
Run Code Online (Sandbox Code Playgroud)

并且在释放导航控制器之后我有

2013-09-19 13:09:32.419 myApp[4690:a0b] *** -[UIView release]: message sent to     deallocated instance 0xa265310
Run Code Online (Sandbox Code Playgroud)

所以...谁知道UIView是什么?它来自何处以及如何处理它?

Che*_*vid 17

iOS 7确实改变了有关tableviews及其委托的一些规则.当然,这并没有突出显示在易于找到的地方.

但基本上,在早期版本的iOS中,您可以选择性地淘汰tableView委托和数据源.不这样做不发送任何错误消息.

从iOS 7开始,你必须在你的dealloc中使用它们,否则会导致崩溃.

- (void)dealloc
{
fetchedResultsController.delegate = nil;
self.searchDisplayController.delegate = nil;
self.searchDisplayController.searchResultsDelegate = nil;
self.searchDisplayController.searchResultsDataSource = nil;
self.tableView.delegate = nil;
self.tableView.dataSource = nil;    
}
Run Code Online (Sandbox Code Playgroud)

如果这解决了您的问题,请告诉我.

  • +1可以节省这么多小时的人们的实时时间!在我的情况下,我还必须把`tableHeaderView`(包含searchBar)弄掉. (2认同)