The Crazy Chimp The Crazy Chimp - 2 years ago 126
Swift Question

Change UISearchBar/Keyboard Search Button Title in Swift

I'm trying to do the equivalent of this but in Swift and I'm running into problems:

  1. No equivalent of
    blocks in swift

  2. The
    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?

Answer Source

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];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download