1

试图覆盖 UISearchBar 的 resignFirstResponder 方法以使取消按钮始终启用:

@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

但是日志什么也没显示!

我像这样使用它

[mySearchBar resignFirstResponder];
4

0 回答 0