3
votes

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 are going in the navigation controller.

In the 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 a crash when trying to release the navigation controller.

In the log, I have these 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 the nav controller, I have

2013-09-19 13:09:32.419 myApp[4690:a0b] *** -[UIView release]: message sent to     deallocated instance 0xa265310

What is the UIView? Where it comes from and how to deal with it?

1

1 Answers

17
votes

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.