覆盖resignFirstResponder失败

时间:2013-02-18 16:22:13

标签: ios xcode uisearchbar resignfirstresponder

尝试覆盖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];

0 个答案:

没有答案