本文介绍了在 Swift 中更改 UISearchBar/键盘搜索按钮标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试做相当于这个 但在 Swift 中,我遇到了问题:
I'm trying to do the equivalent of this but in Swift and I'm running into problems:
- 在 swift 中没有等效的
try/catch
块 if
语句似乎永远不会被评估为真
- No equivalent of
try/catch
blocks in swift - The
if
statement never seems to be evaluated as true
以下是我目前整理的内容:
Here is what I've put together so far:
for searchBarSubview in self.searchBar!.subviews {
if (searchBarSubview.conformsToProtocol(UITextInputTraits)) {
var searchBarTextField = searchBarSubview as UITextField
searchBarTextField.returnKeyType = UIReturnKeyType.Done
}
}
有人知道我哪里出错了吗?
Does anyone have any ideas where I'm going wrong?
推荐答案
我认为你只需要执行以下代码就可以了.有什么理由让您觉得检查 UITextInputTraits
吗?
I think you only need to do the following code and you are good to go. Any reasons why that bothers you to check UITextInputTraits
?
[self.searchBar setReturnKeyType:UIReturnKeyDone];
这篇关于在 Swift 中更改 UISearchBar/键盘搜索按钮标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!