Skip to content

Instantly share code, notes, and snippets.

@henrik
Created June 12, 2010 19:21
Show Gist options
  • Save henrik/435996 to your computer and use it in GitHub Desktop.
Save henrik/435996 to your computer and use it in GitHub Desktop.
Enable the Return key in a UISearchBar even when its text is empty.
// By Henrik Nyh <http://henrik.nyh.se> 2010-06-12 under the MIT license.
#import <Foundation/Foundation.h>
@interface SearchBarStyler : NSObject {
}
+(void)enableReturnKeyWithNoText:(UISearchBar *)searchBar;
@end
#import "SearchBarStyler.h"
@implementation SearchBarStyler
+(void)enableReturnKeyWithNoText:(UISearchBar *)searchBar {
// Really a UISearchBarTextField, but that header is private.
UITextField *searchField = nil;
for (UIView *subview in searchBar.subviews) {
if ([subview isKindOfClass:[UITextField class]]) {
searchField = (UITextField *)subview;
break;
}
}
if (searchField) {
searchField.enablesReturnKeyAutomatically = NO;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment