1

Trying to override resignFirstResponder methode of UISearchBar in order to make Cancel button always enabled:

@interface UISearchBar(alwaysEnableCancelButton)
- (BOOL)resignFirstResponder;
@end

@implementation UISearchBar(alwaysEnableCancelButton)

- (BOOL)resignFirstResponder
{
    // Force the cancel button to stay enabled
    UIView *possibleButton;
    for (possibleButton in self.subviews)
    {
        if ([possibleButton isKindOfClass:[UIButton class]])
        {
            UIButton *cancelButton = (UIButton*)possibleButton;
                [cancelButton setEnabled:YES];
        }


        // Dismiss the keyboard
        if ([possibleButton isKindOfClass:[UITextField class]]) {
            [(UITextField *)possibleButton resignFirstResponder];
        }
    }
    NSLog(@"done");
    return [super resignFirstResponder];
}
@end

But the log shows nothing!

I'm using it like

[mySearchBar resignFirstResponder];
Artem Sultan
  • 459
  • 4
  • 10

0 Answers0