0

我进行了子类化NSSecureTextField和覆盖-(BOOL)becomeFirstResponder,但只有当我的自定义NSSecureTextField第一次获得焦点时它才能正常工作。

4

1 回答 1

0

I think it is not a problem of NSSecureTextField. It is a problem of how a control get focused.

Create a new project and only drag two NSSecureTextField on your view. Set the custom class of one of them to MySecureTextField defined below and keep the other one default. Run the project and change focus between the two NSSecureTextField, you will see the "Get focus" printed when the custom one get focus each time.

Back to your program, please check if the NSSecureTextField is lost focus? Does the resignFirstResponser called?

#import "MySecureTextField.h"

@implementation MySecureTextField

- (id)initWithFrame:(NSRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code here.
    }

    return self;
}

- (void)drawRect:(NSRect)dirtyRect
{
    // Drawing code here.
}

- (BOOL)becomeFirstResponder
{
    NSLog(@"Get focus");
    return [super becomeFirstResponder];
}
@end
于 2013-09-25T07:39:04.430 回答