3

I have a view based NSTableView in which the cells contain a number of controls including text fields and edit fields. When a user tries to click on a control within a cell in order to, for example, start editing a text field, the click's main objective is ignored and the cell gets selected. Another click is then needed to perform the action originally intended, and even this click is subject to a delay before it's taken into account.

How can I avoid this problem and have the row selected and the mouse event forwarded to the control in one go?

tarmes
  • 15,366
  • 10
  • 53
  • 87
  • you can explicitly make first responder and accept the click on to the tableview's cell, and then make a selector that will invoke your method. – Anoop Vaidya Nov 27 '12 at 05:28

2 Answers2

19

I solved this issue by subclassing NSTableView:

@implementation QuickResponseTableView

- (BOOL)validateProposedFirstResponder:(NSResponder *)responder forEvent:(NSEvent *)event
{
    // This allows the user to click on controls within a cell withough first having to select the cell row
    return YES;
}

@end
tarmes
  • 15,366
  • 10
  • 53
  • 87
  • 2
    FWIW, this is the correct answer (Corbin, who wrote the View Based NSTableView ) – corbin dunn May 08 '17 at 16:10
  • 1
    @corbindunn convinced me with "who wrote the View Based NSTableView" and I blithely went on to write a whole of other stuff. And then I noticed that I could no longer select a row. Once, but there the selection would stick. And if there happened to be a textField on the place where I clicked to select the row, it would immediately go into editing mode. Anyway, it took me a few days and a switch to Git, but now I can confidently say: do not return YES on validateProposedFirstResponder: without checking where the event took place, for instance by calling convertPoint:fromView: – Elise van Looij May 29 '17 at 15:31
  • Elise: that is what NSTableView effectively does. I think I've written about that elsewhere...but i need to find the post. – corbin dunn May 30 '17 at 16:12
  • @corbindunn here: http://www.corbinstreehouse.com/blog/2014/04/nstableview-tips-not-delaying-the-first-responder/ – JanApotheker Jul 13 '18 at 08:01
7

Had the same problem. After much struggle, it magically worked when I selected None as against the default Regular (other option is Source List) for the Highlight option in IB! The accepted answer appears to be more specific but a little hacky compared to this.

trss
  • 915
  • 1
  • 19
  • 35