我进行了子类化NSSecureTextField
和覆盖-(BOOL)becomeFirstResponder
,但只有当我的自定义NSSecureTextField
第一次获得焦点时它才能正常工作。
问问题
316 次
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 回答