• 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
Answer: What NSTextField has cursor in it?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Answer: What NSTextField has cursor in it?


  • Subject: Answer: What NSTextField has cursor in it?
  • From: Ed Watkeys <email@hidden>
  • Date: Sat, 6 Dec 2003 08:57:40 -0500

Hi,

Here's code you can use to find the first object in the responder chain that is a subclass of a given class, or nil if there is no matching responder in the responder chain.

Theory of operation: The NSWindow message firstResponder is called _first_Responder, because it returns the first NSResponder in the responder chain. If an event occurs that the first responder doesn't want to process, it typically passes the event to the next responder. A field editor, an instance of NSTextView, is the first responder when an NSTextField has focus. However, somewhere down the responder chain is the NSTextField that the field editor is processing events for.

Keep in mind that the current on-screen object with focus may not be an instance of NSControl. It could be, for example, an NSTextView that you laid out in Interface Builder. There are also classes besides NSTextField that use an editor that is placed at the front of the responder chain; for example, NSTableView uses an NSTextView as a cell editor.

Anyway, here's the code snippet:

NSWindow *w;
Class c;
NSResponder *r;

w = mainWindow;
c = [NSControl class];

for(r = [w firstResponder]; r != nil && ![[r class] isSubclassOfClass:c]; r = [r nextResponder])
;

The variable _r_ will contain the first control in the responder chain that is a subclass of the given class, or nil if there is no control in the chain. Keep in mind that the following expression is true:

[[NSObject class] isSubclassOfClass:[NSObject class]]

Therefore, you can set c in the above code to be a leaf class, such as NSTextField.

Regards,
Ed
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: -(BOOL)isFirewireDisk;(NSString*)path
  • Next by Date: Sudden exit from NSBrowser deleg.
  • Previous by thread: -(BOOL)isFirewireDisk;(NSString*)path
  • Next by thread: Sudden exit from NSBrowser deleg.
  • Index(es):
    • Date
    • Thread