OGeek|极客世界-中国程序员成长平台

标题: ios - 调用`[UISearchBar setReturnKeyType:]`时无法识别的选择器 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 09:51
标题: ios - 调用`[UISearchBar setReturnKeyType:]`时无法识别的选择器

在我们的应用中,对于iOS 7.0、7.0.4和7.0.6用户,我们开始遇到以下错误:
-[UISearchBar setReturnKeyType:]: unrecognized selector sent to instance 0x178a7920
由于Xcode 6.4不再支持7.0、7.0.4和7.0.6模拟器,我们花了点时间弄清楚发生了什么。解释在下面共享。



Best Answer-推荐答案


我们从UISearchBar.h的文档中意识到:

... UISearchBar在iOS 8.0中正式符合UITextInputTraits并在iOS 7.0中 private 符合...

因此8.x对UITextInputTraits具有 public /完全支持,但iOS的7.x版本仅对此提供了 private /潜在的部分支持。

我们开始使用不同的iOS 7.x版本,发现等于或大于iOS 7.1的版本确实支持setReturnKeyType:,而较早的版本则不支持。

似乎a different method在iOS 7的早期版本中使用了(请参阅链接中第二受欢迎的答案),这似乎证实了我们的结论。

因此,对于iOS 7.x版本,我们最终使用了以下命令:

if ([searchBar respondsToSelectorselector(setReturnKeyType]) {
    searchBar.returnKeyType = UIReturnKeyDone; // Pick a type
} else {
    // Call the method from the linked answer above for iOS < 7.1
    // or leave the return key type unchanged.
}

关于ios - 调用`[UISearchBar setReturnKeyType:]`时无法识别的选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31996624/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4