2
A
回答
3
你可以改變你的UISearchBar對象的keyboardType
財產。但是,沒有辦法直接更改returnKeyType
。您可能能夠過濾並手動更改它。檢查UISearchBar的文檔並查看是否可以找到returnKeyType
,因爲這正是您正在尋找的。
2
我做到這樣說:
// -- Basic UISearchBar setup.
self.theSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0,0,320,38)];
[self.theSearchBar setDelegate:self];
[self.view addSubview:self.theSearchBar];
// -- Customize the returnKeyType of the search bar's nested UITextField.
UITextField *searchBarTextField = [[self.theSearchBar subviews] objectAtIndex:1];
searchBarTextField.returnKeyType = UIReturnKeyGo;
希望這是有幫助的。這種方法(即通過索引獲取子視圖)可能會在未來中斷,但現在它可以正常工作。
-1
不要依賴它作爲第二個子視圖,使用isKindOfClass:方法來檢查。這將是更多的iOS更新證明。
for (UIView *subview in self.theSearchBar.subviews) {
if ([subview isKindOfClass:[UITextField class]]) {
[(UITextField *)subview setReturnKeyType:UIReturnKeyGo];
break;
}
}
0
for (UIView *view in _searchBar.subviews){
if ([view isKindOfClass:[UITextField class] ]) {
UITextField *searchTf = (UITextField *)view;
searchTf.returnKeyType = UIReturnKeyDone;
}
}
0
這是工作的iOS 6
UITextField *searchBarTextField = [[searchBarObj subviews] objectAtIndex:1];
searchBarTextField.returnKeyType = UIReturnKeyDefault;
[searchBarTextField setEnablesReturnKeyAutomatically:NO];
這是工作的iOS 7
for (UIView *subview in self.searchBar.subviews)
{
for (UIView *subSubview in subview.subviews)
{
if ([subSubview conformsToProtocol:@protocol(UITextInputTraits)])
{
UITextField *textField = (UITextField *)subSubview;
[textField setKeyboardAppearance: UIKeyboardAppearanceAlert];
textField.returnKeyType = UIReturnKeyDone;
break;
}
}
}
相關問題
- 1. 的UISearchBar搜索按鈕
- 2. UISearchBar - 什麼是「搜索結果按鈕」?
- 3. 更改UISearchBar搜索按鈕上的UITableView數據源點擊
- 4. 搜索欄從iphone上的搜索按鈕擴展
- 5. 上的取消按鈕按下的UISearchBar的 - 在iPhone
- 6. UISearchbar上的取消按鈕
- 7. 我如何解僱鍵盤上關於UISearchBar的鍵盤上的搜索按鈕?
- 8. 可可觸摸 - UISearchBar鍵盤 - 隱藏'搜索'按鈕
- 9. 如何禁用/啓用UISearchBar鍵盤的搜索按鈕?
- 10. 自定義搜索結果按鈕具有的UISearchBar
- 11. Iphone UISearchBar取消按鈕故障
- 12. 當字段爲空時,爲UISearchBar啓用「搜索」按鈕? (iOS 7)
- 13. 無法隱藏鍵盤單擊搜索按鈕在UISearchBar
- 14. 更改UISearchBar /鍵盤搜索按鈕標題
- 15. 使用UISearchBar搜索
- 16. UISearchBar搜索記錄
- 17. iPhone - 搜索欄上的自定義按鈕?
- 18. 如何啓用UI搜索欄上的取消按鈕iPhone
- 19. 在按鈕上搜索NULL值按下
- 20. 按Uisearchbar x按鈕按下
- 21. 搜索時的UISearchBar背景
- 22. Bing搜索框內的搜索按鈕
- 23. 搜索鍵盤中的搜索按鈕
- 24. 在UISearchBar上執行搜索NSArray
- 25. Magento上的搜索按鈕破解
- 26. 手機上的搜索按鈕事件
- 27. 編程鍵盤上的搜索按鈕
- 28. 把搜索框搜索按鈕的左側點擊按鈕
- 29. 搜索按鈕+ gridview
- 30. VB.net搜索按鈕
感謝,但不幸的是在搜索欄中沒有這個屬性.. 。:( – SpaceDog 2010-07-17 02:21:51