{"id":3638,"date":"2014-04-26T18:51:07","date_gmt":"2014-04-27T02:51:07","guid":{"rendered":"http:\/\/www.corbinstreehouse.com\/blog\/2014\/04\/nstableview-tips-not-delaying-the-first-responder\/"},"modified":"2018-11-03T13:36:24","modified_gmt":"2018-11-03T20:36:24","slug":"nstableview-tips-not-delaying-the-first-responder","status":"publish","type":"post","link":"https:\/\/www.corbinstreehouse.com\/blog\/2014\/04\/nstableview-tips-not-delaying-the-first-responder\/","title":{"rendered":"NSTableView Tips: Not delaying the first responder"},"content":{"rendered":"<p id=\"top\" \/>\n<p>I have a little home-brew Cocoa app for making Cyr Wheel patterns. The UI is built with an NSTableView and looks like this:<\/p>\n<p>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.corbinstreehouse.com\/blog\/wp-content\/uploads\/2014\/04\/Screen-Shot-2014-04-26-at-7.31.00-PM.png\" width=\"827\" height=\"335\" alt=\"Screen Shot 2014-04-26 at 7.31.00 PM.png\" \/><\/p>\n<p>Now normally when you try to directly click on one of the NSTextFields the table will first select the row. <b>Then<\/b> 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:<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow:auto;width:auto;;\">\n<pre style=\"margin: 0; line-height: 125%\">\n<span style=\"color: #000080; font-weight: bold\">-<\/span> (<span style=\"color: #000080; font-weight: bold\">BOOL<\/span>)validateProposedFirstResponder:(NSResponder *)responder forEvent:(NSEvent *)event {\n<span style=\"color: #000080; font-weight: bold\">   return<\/span> YES; <span style=\"color: #008800; font-style: italic\">\/\/ no delay<\/span>\n}\n<\/pre>\n<p>\n<\/div>\n<p>\nNSTableView&#8217;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&#8217;t an already selected row, it returns NO; this causes the table to get the mouseDown: and do the selection logic. br\/&gt;I don&#8217;t care what control was clicked; I want it to go through without selecting, and always return YES.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have a little home-brew Cocoa app for making Cyr Wheel patterns. The UI is built with an NSTableView and looks like this: Now normally when you try to directly click on one of the&#8230; <a class=\"read-more\" href=\"https:\/\/www.corbinstreehouse.com\/blog\/2014\/04\/nstableview-tips-not-delaying-the-first-responder\/\">[read more]<\/a><\/p>\n","protected":false},"author":1,"featured_media":3637,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6,86],"tags":[63,130,72],"class_list":["post-3638","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cocoa","category-coding","tag-cocoa","tag-objc","tag-programming"],"jetpack_featured_media_url":"https:\/\/www.corbinstreehouse.com\/blog\/wp-content\/uploads\/2014\/04\/Screen-Shot-2014-04-26-at-7.31.00-PM.png","jetpack_shortlink":"https:\/\/wp.me\/p8zn47-WG","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/posts\/3638","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/comments?post=3638"}],"version-history":[{"count":3,"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/posts\/3638\/revisions"}],"predecessor-version":[{"id":5170,"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/posts\/3638\/revisions\/5170"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/media\/3637"}],"wp:attachment":[{"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/media?parent=3638"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/categories?post=3638"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/tags?post=3638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}