Question

For some reason the UISearchDisplayController delegate method, willUnloadSearchResultsTableView, stopped working in iOS7.

It works correctly on my 4s device running iOS 6.1.3, but not in the iOS7 simulator. I've tried both 7.0.3 with Xcode 5.0 and 7.1 with Xcode 5.1 Beta 5 (5B103i).

To test this open the sample project in Xcode 5, Simple UISearchBar with State Restoration, xcdoc://ios/samplecode/TableSearch/Introduction/Intro.html

1) Locate the search delegate methods in APLViewController.m and add below them:

- (void)searchDisplayController:(UISearchDisplayController *)controller willUnloadSearchResultsTableView:(UITableView *)tableView {

    NSLog(@"willUnloadSearchResultsTableView");
}

2) Run the app on an iOS6 device and punch some text into the search view and then tap the Cancel button. You should see the text "willUnloadSearchResultsTableView" in the console log.

3) Now try running the same code on an iOS7 device/simulator. This time, when you tap the cancel button, you won't see anything written to the console log.

Can anyone shed light on this?

It's a real problem for me, because I've added a custom search item to the Tab navigator and update the item-label with the number of search results. I restore the original tab item-label when the user unloads the search view, but it doesn't get restored in iOS7.

Was it helpful?

Solution

It could be that Apple changed the table view caching mechanism and doesn't unload the table in the same pattern as before.

If you believe that this is a bug on Apple's side, make sure to open a bug report at https://bugreport.apple.com.

In the meantime, try moving your code to the following delegate methods:

– searchDisplayController:willShowSearchResultsTableView:
– searchDisplayController:didShowSearchResultsTableView:
– searchDisplayController:willHideSearchResultsTableView:
– searchDisplayController:didHideSearchResultsTableView:
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top