• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Determining which control has focus
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Determining which control has focus


  • Subject: Re: Determining which control has focus
  • From: Ken Thomases <email@hidden>
  • Date: Thu, 25 Oct 2012 15:02:53 -0500

On Oct 25, 2012, at 2:43 PM, Jens Alfke wrote:

> On Oct 25, 2012, at 11:59 AM, Erik Stainsby <email@hidden> wrote:
>
>> I have a window which contains half a dozen text fields and three table views. I'd like to be able to use a single key-combo to trigger an insert into the current table. To make this work I need to be able to recognize each tableView distinctly, obviously. I also need to recognize if the current focus is not within one of the tables, which case I will handle differently.
>
> Call NSWindow.firstResponder to find which view has focus. (Although be careful, as the first responder may not be an NSView; for instance, it could be the NSWindow itself if no view has focus.) Then walk up the view hierarchy until you find a view you’re interested in.
>
> If a text field has focus, though, you’ll find the firstResponder is actually an NSTextView which is the window’s shared fieldEditor. In that case, the delegate of that view will be the actual NSTextField that is considered to have focus.

Another approach is to make the key-combo the key equivalent for an item in your app's menus.  Set the action method of that menu item to be something which is implemented by the table views which are supposed to support this feature.  Then, the action will be directed to the table view that's in the responder chain, if there is one; if there isn't, then the menu item will be automatically disabled.  Alternatively, if you want to do something else when no table view is focused, then make the window controller or your app delegate implement the action method to do that other thing.

Regards,
Ken


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >Determining which control has focus (From: Erik Stainsby <email@hidden>)
 >Re: Determining which control has focus (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: Determining which control has focus
  • Next by Date: Object not being drawn in Cmd + N window. Why?
  • Previous by thread: Re: Determining which control has focus
  • Next by thread: Re: Determining which control has focus
  • Index(es):
    • Date
    • Thread