Skip to content

Instantly share code, notes, and snippets.

@danielgomezrico
Created January 30, 2015 19:00
Show Gist options
  • Save danielgomezrico/11526be8244a9137b30c to your computer and use it in GitHub Desktop.
Save danielgomezrico/11526be8244a9137b30c to your computer and use it in GitHub Desktop.
Enable search button on keyboard with empty value on UISearchBar
#import <UIKit/UIKit.h>
@interface UISearchBar (UISearchBar_EnableEmptySearch)
- (void)enableEmptySearch;
@end
@implementation UISearchBar (UISearchBar_EnableEmptySearch)
- (void)enableEmptySearch {
UITextField *searchBarTextField = nil;
for (UIView *subView in self.subviews){
for (UIView *secondLeveSubView in subView.subviews){
if ([secondLeveSubView isKindOfClass:[UITextField class]])
{
searchBarTextField = (UITextField *)secondLeveSubView;
break;
}
}
}
searchBarTextField.enablesReturnKeyAutomatically = NO;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment