ios - "Fixed"奇怪的 "unrecognized selector sent to instance"崩溃发生在 iOS8 beta5

标签 ios xcode ios8 first-responder

我的应用在 iOS7 上运行良好,但在 iOS8 上崩溃。

我见过关于这个主题的各种问题,但从未找到好的解决方案。

我有一个使用 UITableViewController 的应用程序,UITableViewController 有一个 SearchDisplayController 实例调用 m_searchDisplayController。

当我第一次点击搜索栏进行搜索时,表格 View 随后显示结果,搜索栏 resignFirstResponder。但我再次点击搜索栏时,应用程序崩溃了:

-[MyFavoritesViewController _searchController]: unrecognized selector sent to instance

这是堆栈:

enter image description here

然后我尝试将 _searchController 方法添加到 MyFavoritesViewController 类,如下所示:

 - (UISearchDisplayController *)_searchController
 {
      return nil;
 }

除了搜索栏的 textField 无法输入外,应用程序工作正常。所以我尝试这样做:

 - (UISearchDisplayController *)_searchController
 {
      return m_searchDisplayController;
 }

另一个崩溃消息显示:

-[UISearchDisplayController _searchBarShouldFinalizeBecomingFirstResponder]: unrecognized selector sent to instance

我不知道如何定位错误代码,谁有解决方案?提前致谢。

我的情况:

我在 UISearchBar 中做了一些 hack,我将 searchBar 的 textField 的委托(delegate)更改为某个对象。最初,系统的“_searchController”方法将调用 searchBar 的 textField 的委托(delegate),但现在,它将调用我的对象然后崩溃.我希望它有所帮助。

最佳答案

如果您尝试通过将委托(delegate)分配给 UISearchBar textField 来响应被点击的清除按钮,这在 iOS8 中会中断。尝试另一种技术。

也许是 UISearchBarDelegate 的方法

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

现在,如果您需要对最后一个退格键做出不同的响应,那么您将不得不想出一些变通办法,例如响应退格键,或者添加一个退格键无法删除但清除确实会删除的不可见字符.这些只是 2 条建议。

关于ios - "Fixed"奇怪的 "unrecognized selector sent to instance"崩溃发生在 iOS8 beta5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25544168/

相关文章:

ios - 在 Apple WatchKit 中使用核心位置

swift - 复制 Instagram 搜索式滑动标签

ios - Swift - 搜索栏初始加载

ios - iOS 如何根据信标识别应用程序?

ios - 为什么UIActionSheet在UIInterfaceOrientationPortraitUpsideDown中是倒着显示的?

ios - 如何使用 cocoa pod 的 Storyboard引用?

ios - 如何查找我的 mac 中是否安装了 cocoaPods

ios - 仅通过Wifi测试iOS连接

ios - 如何实现所需的横向和纵向布局(快速)

objective-c - 在 iOS 8 中,如何将行操作按钮添加到 UITableViewCell 的左侧