Corbin Dunn
Redwood Monkey

NSTableView Tips: Not delaying the first responder

Cocoa, Coding

I have a little home-brew Cocoa app for making Cyr Wheel patterns. The UI is built with an NSTableView and looks like this:

Screen Shot 2014-04-26 at 7.31.00 PM.png

Now normally when you try to directly click on one of the NSTextFields the table will first select the row. Then a second click will allow you to start editing. For most tables, this is the behavior you want. For something like what I have, I want to avoid this, and allow the first responder to go through. This can easily be done by subclassing NSTableView and overriding:

- (BOOL)validateProposedFirstResponder:(NSResponder *)responder forEvent:(NSEvent *)event {
   return YES; // no delay
}

NSTableView’s default logic is a bit complex that allows things to go through or not based on several properties. This method is declared in NSResponder.h, and it is sent up the responder chain when the text field itself attempts to become first responder. When NSTableView gets it, it does some determination to determine if it should go through or not. If it wasn’t an already selected row, it returns NO; this causes the table to get the mouseDown: and do the selection logic. br/>I don’t care what control was clicked; I want it to go through without selecting, and always return YES.

Previous Post
no_thumbnail
How to make a cyr wheel: Insert detail
Next Post
NSTableView Tips: View Controller per row

2
Leave a Reply

avatar
500
2 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
aure Recent comment authors
  Subscribe  
Notify of
aure
Guest
aure

woohoo!
Most overlooked method ever. Thanks a lot, that’s *really* helpful. I made horrible hacks to achieve the (somewhat) same result in the past!

aure
Guest
aure

more more more more Cocoa posts please :D
WWDC demo ?

(c) 2008-2018 Corbin Dunn

Privacy Policy

Subscribe to RSS feeds for entries.

67 queries. 0.538 seconds.

Log in