Frage

I have a custom NSTextField, where I'm implementing some rounded corners.

Pressing the "TAB" key does not go to the next NSTextField (or selectable control) in the window. Weird. Why would it do that? Is there something special I need to add to enable the app to go through the other controls when pressing "TAB"?

War es hilfreich?

Lösung 2

Seems like it was my fault.

I was incorporating delegate calls within the custom class for textDidBeginEditing: and textDidEndEditing:, in order to maintain the placeholder text when the user tabs out of the field, but I wasn't calling the respective super class' methods as well.

After including the call to [super textDidEndEditing...] and [super textDidBeginEditing...] tabbing works fine.

Andere Tipps

Hopefully you've set the nextKeyView either programatically or in Xcode's interface builder, like so:

set nextKeyView from one text field to the next

My solution is not a great one, but works:

Subclass NSTextView

#import <Cocoa/Cocoa.h>

@interface NMTextView : NSTextView

@end


#import "NMTextView.h"

@implementation NMTextView

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"

- (void)keyDown:(NSEvent *)theEvent{

    switch ([theEvent keyCode]) {
        case 36:{
            if (([theEvent modifierFlags] & NSCommandKeyMask))
                //something for Ctrl+Enter
            else
                [super insertNewlineIgnoringFieldEditor:self];
        }break;

        case 48:
            //[self nextKeyView] = _NSClipViewOverhangView
            //[[self nextKeyView] nextKeyView] = NSTokenField (in my case)
            // or something different
            [[[self nextKeyView] nextKeyView] becomeFirstResponder];
            //also http://stackoverflow.com/a/3008622/1067147
        break;

        case 53:
            [_target performSelector:_actionEsc withObject:self];
        break;

        default:// allow NSTextView to handle everything else
            [super keyDown:theEvent];
        break;
    }
}

#pragma clang diagnostic pop

@end
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top