caipivara
1/30/2015 - 7:00 PM

Enable search button on keyboard with empty value on UISearchBar

Enable search button on keyboard with empty value on UISearchBar

@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;

}
#import <UIKit/UIKit.h>

@interface UISearchBar (UISearchBar_EnableEmptySearch)

- (void)enableEmptySearch;

@end