问题
Hi, guys.
I have some trouble with new uisearchbar in iOS 7
in my app a have tableview with search bar in tableHeaderView it is handmade(added programmatically) - tableviewcontroller in storyboard, in method viewDidLoad i add searchDisplayController with my custom searchbar inherited from UISearchBar.
all things going in navigation controller.
in logic of my app in some point i release this nav controller sending dismissViewController
In ios 6 it works perfect.
but in ios 7 i get crash when trying release navigation controller.
in log i have interesting lines...
to the end of viewDidLoad i add this:
for (UIView *view in self.view.subviews) {
NSLog(@"%@ %p", [view.class description], view);
}
in ios 6 i have only this
2013-09-19 12:40:40.553 myApp[4182:c07] KRSearchBar 0x988bdd0
in 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
and after releasing nav controller i have
2013-09-19 13:09:32.419 myApp[4690:a0b] *** -[UIView release]: message sent to deallocated instance 0xa265310
so...who's know what the UIView ? where it comes from and how to deal with it?
回答1:
iOS 7 did change some rules concerning tableviews and their delegate. Of course, this is not highlighted somewhere easy to find.
But basically, in earlier version of iOS, you could nil out tableView delegate and datasource optionally. Not doing so was not sending any error message.
From iOS 7, you MUST nil them in your dealloc otherwise it can lead to this crash.
- (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;
}
Let me know if this solved your issue.
来源:https://stackoverflow.com/questions/18890716/new-uisearhbar-in-ios-7