2

My UISearchbar has a visible cancel button.

self.searchBar.showsCancelButton = YES;

When I do

[self.searchBar resignFirstResponder];

the cancel button stops working (enabled = NO)

I am using this hack to forcefully enable the cancel button (category on UISearchbar):

-(UIButton *)cancelButton
{
    for (UIView *v in self.subviews) {
        for (UIView *subview in v.subviews) {
            if ([subview isKindOfClass:[UIButton class]])
            {
                return (UIButton *)subview;
            }
        }
    }
    ELog(@"Couldn't find cancel button");
    return nil;
}

But it doesn't seem the legit way to do it. Are there better ways?

Avba
  • 14,822
  • 20
  • 92
  • 192

0 Answers0