Select Next Nstextfield with Tab Key in Swift

Select next NSTextField with Tab key in Swift

You have to connect your textField nextKeyView to the next textField through the IB or programmatically:

textField1.nextKeyView = textField2

Sample Image

Select next row when Enter is pressed while editing a NSTextField inside a NSTableView

I would use the NSControlTextEditingDelegate method

- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command

with the text field to detect the enter key and

- (void)editColumn:(NSInteger)columnIndex row:(NSInteger)rowIndex withEvent:(NSEvent *)theEvent select:(BOOL)flag

to select the next row in the table view.

TAB in custom NSTextField does not put focus on another control

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.

How do I manually set the key-view in a cocoa app?

From the documentation of func selectKeyView(following view: NSView):

Sends the nextValidKeyView message to view and, if that message returns an NSView object, invokes makeFirstResponder(_:) with the returned object.

To select targetView, skip nextValidKeyView and call makeFirstResponder(_:).

self.window?.makeFirstResponder(targetView)


Related Topics



Leave a reply



Submit