TAB in custom NSTextField does not focus on another control

I have a custom NSTextField where I implement some rounded corners.

Pressing the TAB key does not advance to the next NSTextField (or selectable control) in the window. Weird Why do this? Is there anything special I need to add so that the application can go through other controls when I press "TAB"?

+6
source share
3 answers

It seemed like it was my mistake.

I included delegate calls in the user class for textDidBeginEditing: and textDidEndEditing: to support the placeholder text when the user inserts a tab from the field, but I did not call the appropriate superclass methods as well.

After turning on the call [super textDidEndEditing...] and [super textDidBeginEditing...] tab works fine.

+2
source

I hope you installed nextKeyView either programmatically or in the constructor of the Xcode interface, for example:

set nextKeyView from one text field to the next

+11
source

My solution is not very good, but it 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 
+1
source

Source: https://habr.com/ru/post/919844/


All Articles