In a view-based NSTableView, how do I control the first responder with one click?

Presentation-based NSTableViews seem to have only standard behavior, where in order to make the text field inside the table the first responder, the user must either double-click, or click, or "keep calm."

However, given the flexibility-based NSTableViews proposal, this behavior is not always desirable, as there are currently many different and complex applications than just executing an "old school" table.

How can I easily make a control (possibly in a cell along with other controls) inside an NSTableView based on the presentation of the first responder with one click?

+7
source share
1 answer

To solve this problem, override this method in NSTableView:

@interface NSResponder (NSControlEditingSupport) /* This is a responder chain method to allow controls to determine when they should become first responder or not. Some controls, such as NSTextField, should only become first responder when the enclosing NSTableView/NSBrowser indicates that the view can begin editing. It is up to the particular control that wants to be validated to call this method in its -mouseDown: (or other time) to determine if it should attempt to become the first responder or not. The default implementation returns YES when there is no -nextResponder, otherwise, it is forwarded up the responder chain. NSTableView/NSBrowser implements this to only allow first responder status if the responder is a view in a selected row. It also delays the first responder assignment if a doubleAction needs to (possibly) be sent. 'event' may be nil if there is no applicable event. */ - (BOOL)validateProposedFirstResponder:(NSResponder *)responder forEvent:(NSEvent *)event NS_AVAILABLE_MAC(10_7); @end 

And immediately return YES so that you can quickly make the first interrogator. The table โ€œdelaysโ€ the creation of the first responder if the text field was deleted and does not allow it to be executed unless the first row has been selected.

+21
source

All Articles