Why doesn't NSTextField redraw the background of focused fields?

I got confused about a strange problem. I have two NSTExtField representing username and password. When I get the wrong username and password combination, I set the instance variable specified in the view controller containing these two fields. Then I use key value monitoring to run the following method when the instance variable changes:

- (void)handleCredentialsValidityToggle {
    if ([self areCredentialsValid]) {
        [passwordField setBackgroundColor:[NSColor colorWithCalibratedRed:1.0 green:1.0 blue:1.0 alpha:1.0]];
        [usernameField setBackgroundColor:[NSColor colorWithCalibratedRed:1.0 green:1.0 blue:1.0 alpha:1.0]];
    } else {
        [passwordField setBackgroundColor:[NSColor colorWithCalibratedRed:1.0
                                                                    green:1.0
                                                                     blue:0.35
                                                                    alpha:1.0]];
        [usernameField setBackgroundColor:[NSColor colorWithCalibratedRed:1.0
                                                                    green:1.0
                                                                     blue:0.35
                                                                    alpha:1.0]];
    }
}

This works fine while the field is not active. In other words, if I change one of the fields, keep it in focus with the cursor inside and try to authenticate (by clicking the menu item), the field with focus is not updated to the new background color, and the field is without focus.

, , :

[passwordField drawCell:[passwordField cell]];
[usernameField drawCell:[usernameField cell]];

- . - , ? !

+3
1

, . NSTextFieldCell editWithFrame:inView:editor:delegate:event:.
(, , , setDrawsBackground:YES.)

-1

All Articles