"Fixed" strange "unrecognized selector sent to instance" crash on iOS8 beta5

My app works fine on iOS7 but crashes on iOS8.

I have seen various questions on this topic but have not found a good solution for this.

I have an application where, using UITableViewController and UITableViewController, there is a request for an instance of SearchDisplayController m_searchDisplayController.

When I first click on the search bar to find something, the table view then shows the result, and the search bar resignFirstResponder. But I click on the search bar again, the app crashes:

-[MyFavoritesViewController _searchController]: unrecognized selector sent to instance

      

Here is the stack:

enter image description here

Then I try to add a _searchController method to the MyFavoritesViewController class like:

 - (UISearchDisplayController *)_searchController
 {
      return nil;
 }

      

Then the app works fine except the search stringField cannot type. So I try this:

 - (UISearchDisplayController *)_searchController
 {
      return m_searchDisplayController;
 }

      

And one more alarm message:

-[UISearchDisplayController _searchBarShouldFinalizeBecomingFirstResponder]: unrecognized selector sent to instance

      

I don't know how to find the error code and who has a solution about this? Thanks in advance.

My situation:

I am doing a hack in UISearchBar and I am changing the textField delegate to textBield for some object. Initially the system method "_searchController" calls the delegate from textField to search, but now it will call my object and then fail, I hope this helps.

+3


source to share


2 answers


If you are trying to respond to a clear button click by assigning a delegate to the UISearchBar text field, it breaks in iOS8. Try another method.

Maybe UISearchBarDelegate 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 react differently to the last backspace key, you will have to come up with some work, like answering the backspace key, or adding an invisible character that cannot remove the backspace, but clear does.That's just 2 suggestions.

0


source


I have the same problem. Compile your project with SDK 8.0+ and the problem goes away. No code changes required.



Another solution, do not assign the UITextField that is in the UISearchBar delegate, and that additional functionality (if any) will be moved elsewhere.

0


source







All Articles