• 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: Talking to FirstResponder
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Talking to FirstResponder


  • Subject: Re: Talking to FirstResponder
  • From: "John C. Randolph" <email@hidden>
  • Date: Mon, 13 Jan 2003 15:44:13 -0800

On Saturday, January 11, 2003, at 03:47 PM, Colin Jackson wrote:

Hi,
I'm in the middle of writing my first Cocoa app. My App is probably one of the most complex things I have ever programmed but I am slowly learning that Cocoa usually has a solution to all my problems - my app is based around a text editor which could probably be made in about 30 seconds from start to finish if you rehearsed it a few times.

Anyway, so here is the problem. I need to perform actions on whatever the FirstResponder is every-so-often. It's easy enough to attach a button to a FirstResponder in IB but how can I call the same set of actions from within the program?

I tried this:
[[[NSApp keyWindow] firstResponder] print];

But it doesn't work:
warning: 'NSResponder' does not respond to print
at compile time
and
*** -[NSWindow print]: selector not recognized
at runtime

By the way, the actions I actually want to perform are all the ones to do with spell-checking.

Help would be much appreciated.

Neither NSResponder nor NSWindow have a method named "print". NSWindow and NSView both have a method named "print:" (note that the colon is part of the method name.)

To silence the compile-time warning, you could try:

[(NSWindow *)[[NSApp keyWindow] firstResponder] print];

or declare the -print: method in a category of NSResponder:

@interface NSResponder (shutUp)

- (void) print:(sender);

@end

@implementation NSResponder (shutUp)

- (void) print:(sender) {};

@end


John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
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.

References: 
 >Talking to FirstResponder (From: Colin Jackson <email@hidden>)

  • Prev by Date: Re: Toolbar in Mail (was: Aqua Human Interface and Safari)
  • Next by Date: Bottom part of the Interface Builder size inspector and window
  • Previous by thread: Re: Talking to FirstResponder
  • Next by thread: Syntax Coloring and NSTextStorage
  • Index(es):
    • Date
    • Thread