3

My app works fine on iOS7,but crashes on iOS8.

I've seen various question on this topic but never found a good solution for it.

I have an App that's using UITableViewController and UITableViewController has an SearchDisplayController instance call m_searchDisplayController.

When firstly I click on the search bar to search something, the table-view then show the result, and the search bar resignFirstResponder.But again I click on the search bar,the app crashes:

-[MyFavoritesViewController _searchController]: unrecognized selector sent to instance

Here is the stack:

enter image description here

Then I try to add _searchController method to MyFavoritesViewController class,like this:

 - (UISearchDisplayController *)_searchController
 {
      return nil;
 }

Then app works OK except search bar's textField cannot be inputing.So I try this:

 - (UISearchDisplayController *)_searchController
 {
      return m_searchDisplayController;
 }

And another crash message shows:

-[UISearchDisplayController _searchBarShouldFinalizeBecomingFirstResponder]: unrecognized selector sent to instance

I don't know how to locate the error code, and anyone has solution about this? Thanks in advance.

My situation:

I do some hack in UISearchBar and I change the delegate of searchBar's textField to some object.Originally, the "_searchController" method of system will call to delegate of searchBar's textField, but now, it will call to my object and then crash. I hope it helps.

ylovesy
  • 904
  • 1
  • 8
  • 21

2 Answers2

2

If you're trying to respond to the clear button being tapped by assigning a delegate to the UISearchBar textField this breaks in iOS8. Try another technique.

Maybe the UISearchBarDelegate's method

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
    // fired whenever the text is changed, or clear tapped
    if (searchText.length == 0) {
       // Do something
    }
}

Now if you need to respond differently to a last backspaced key then you will have to figure some work around, like responding to a backspace key, or adding an invisible character that the backspace can't remove, but the clear does remove. These are just 2 suggestions.

SmileBot
  • 19,393
  • 7
  • 65
  • 62
0

I've got the same problem. Compile your project with SDK 8.0+ and the problem will disappear. No code changes required.

Another solution, do not assign UITextField that is in UISearchBar delegate and that additional functional (if you have) move to other places.