views:

707

answers:

4

Using iPhone SDK 3.0, I wish to allow text entry with (optional) completion options that appear as typing is occurring, i.e. also allowing freeformat entry. As such I am using a UISearchBar (which has the text change events) and a UISearchDisplayController to present options.

The problems is I want the DONE button to say DONE and not SEARCH, however I cannot find a way to set that. Clearly I feel I am missing something, or Interface Builder of the SDK API would have some property to set.

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

A: 

Odd, UISearchBar should support the UITextInputTraits interface like UITextField and UITextView do (it doesn't say it does in the documentation) and thus should have returnKeyType. I'd try it anyway.

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

Epsilon Prime
A: 

Just had to implement exactly this and couldn't find any great answers anywhere... so I thought I'd provide some insight. Stepping through the debugger and digging into UISearchBar it is pretty obvious. I just ended up finding the UITextView within the uisearchbar subviews and at that point then you should be able to set the returnkeytype on that UITextView once you get a handle on it.

Psuedocode- UISearchBarObject.SubViewAtIndexOfUITextField.ReturnKeyType = UIReturnKeyType.Done

Pimp Juice McJones
Hmmm... lame that I gave the answer but didn't get the credit... do people really need the code spoon fed to them verbatim???
Pimp Juice McJones
+1  A: 

Hi buddy,

Put this code in viewDidLoad.

- (void)viewDidLoad {
...

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

...
}
wal
A: 

+1 For wal's answer, but to be on the safe side, and properly react to possible changes in the view hierarchy in further releases consider using this code:

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