• 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: Make NSTextField only send action on <Return>
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Make NSTextField only send action on <Return>


  • Subject: Re: Make NSTextField only send action on <Return>
  • From: Jens Bauer <email@hidden>
  • Date: Fri, 5 Sep 2003 22:35:38 +0200

Hi Henry,

Thankyou for the quick and accurate reply! :)

I'll try it out immediately. I had a look at the NSTextField delegate methods earlier, but I didn't find any information on how to examine the 'reason'.

I appreciate your help very much, thanks! :)

On Friday, Sep 5, 2003, at 20:02 Europe/Copenhagen, Henry McGilton wrote:

On Friday, September 5, 2003, at 09:50 AM, Jens Bauer wrote:

I have a NSTextField in my interface, and would like it to send an action, but only if the Return key is pressed.

Take a look at the text delegate methods defined in NSControl.
Using a delegate, you can determine what text movement action
was used to end the editing, and then you can decide what to
do with the thing. Set your controller object to be a delegate of the
text field, and implement the controlTextDidEndEditing method.

Something like this:

- (void)controlTextDidEndEditing:(NSNotification *)aNotification
{
NSControl *textfield = [aNotification object]; // tells you the text field sending the notification
NSDictionary *dict = [aNotification userInfo]; // get the user info dictionary from the notification
NSNumber *reason = [dict objectForKey: @"NSTextMovement"]; // get the text movement number from the dictionary
int code = [reason intValue]; // get the text movement code

if (code == NSReturnTextMovement) { // deal with return
;
} else if (code == NSTabTextMovement) { // deal with tab
;
} // and so on and so on
}

The set delegate to text field is defined in NSTextField. The
delegate methods are described (in a very sketchy way) in NSControl,
even though NSControl does not actually have a delegate. The text
movement codes are defined in NSText, and also in the App Kit
Types and Constants under 'Enumerations'. And there is some
more sketchy information in the documentation for NSNotification.

I don't know if there is any actual description in one place of all
the things that you can get out of the NSNotification user info
dictionary --- I had to guess at this stuff and kind of flail
around until it worked --- not what I call engineering . . .

Well, I've been programming that way for several years (before using Mac), partly by disassembling an operating system, heh.. -So don't worry. ;)


Love,
Jens
_______________________________________________
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: 
 >Re: Make NSTextField only send action on <Return> (From: Henry McGilton <email@hidden>)

  • Prev by Date: Multiple controls in one matrix cell?
  • Next by Date: Re: Generating Unique ID
  • Previous by thread: Re: Make NSTextField only send action on <Return>
  • Next by thread: Second Java process starts up for certain operations, but not with Java Bridge?
  • Index(es):
    • Date
    • Thread