Using a UISearchBar with showCancelButton=YES on iOS 5. Would like the cancel button to stay enabled when the keyboard drops down. Using the following code seems not to work:<
Just to improve upon what Kurt Spindler said on his post. Though this might not be superior but it is more contained. I use dispatch to do the same thing.
-(void)searchBarTextDidEndEditing:(UISearchBar *)searchBar{
for (UIView *subview in searchBar.subviews)
{
if ([subview isKindOfClass:[UIButton class]])
{
int64_t delayInSeconds = .001;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
UIButton * cancelButton = (UIButton *)subview;
[cancelButton setEnabled:YES];
});
break;
}
}
}
This should work for everyone who needs help keep cancel enabled. Make sure that you hide it later either with the cancel or Search clicked.
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{
[searchBar resignFirstResponder];
[searchBar setShowsCancelButton:NO animated:YES];
}