IPhone Text entry with end and DONE button (not search)

Using the iPhone SDK 3.0, I want to allow text input with (optional) completion parameters that appear as I type, i.e. also allows freeformat recording. So I use UISearchBar (which has text change events) and UISearchDisplayController to represent the options.

The problem is that I want the DONE button to say DONE and not SEARCH, however I can't find a way to set it. Obviously I feel like something is missing, or the Interface Builder API SDK will have some kind of property to install.

I have seen other apps (in the store) that achieve the result I want (free write, complete, DONE button), so maybe there is an alternative approach I am missing. Thanks in advance for any pointers.

+2


source to share


4 answers


+1 For wal's answer, but just to be safe and to react correctly to possible changes in the view hierarchy in future versions, consider using this code:



NSArray *subviews = [<searchBar> subviews] ;
for(id subview in subviews) {
    if([subview isKindOfClass:[UITextField class]]) {
        [(UITextField*)subview setReturnKeyType:UIReturnKeyDone];
    }
}

      

+5


source


Just needed to implement exactly this and couldn't find any great answers anywhere ... so I thought I'd give some insight. After going through the debugger and digging into the UISearchBar, it's pretty obvious. I just discovered a UITextView in the subviews of a uisearchbar and at this point you will need to set the return type on that UITextView as soon as you get a handle on it.



Psuedocode- UISearchBarObject.SubViewAtIndexOfUITextField.ReturnKeyType = UIReturnKeyType.Done

+2


source


Place this code in viewDidLoad.

- (void)viewDidLoad {
...

NSArray *subviews = [self.searchDisplayController.searchBar subviews] ;
UITextField *searchField = [subviews objectAtIndex:([subviews count]-2)];
[searchField setReturnKeyType:UIReturnKeyDone];

...
}

      

+1


source


Odd, UISearchBar must support UITextInputTraits interface like UITextField and UITextView (it doesn't say what it does in the documentation) and therefore must have returnKeyType . I would try anyway.

If it doesn't, it is possible that one of the objects that the UISearchBar uses has this option.

0


source







All Articles