• 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: firstResponder and multiple NSTextFields
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: firstResponder and multiple NSTextFields


  • Subject: Re: firstResponder and multiple NSTextFields
  • From: Michael Clark <email@hidden>
  • Date: Wed, 24 Aug 2005 23:24:26 -0400

Hi.

If the formatter idea doesn't work out, here is another suggestion:

Set your controller class (the window controller for this license window/sheet) as the delegate of the license textfields.
Have outlets in the controller class to the various textfields that make up the license fields.


Implement the controlTextDidChange: delegate method.

You could do something like this:

- (void)controlTextDidChange: (NSNotification*)aNotif;
{
    id notif_obj = [aNotif object];

if (notif_obj == licenseFieldOne)
{
NSString* val = [notif_obj stringValue];
// Validate the string thus far
// If valid, end editing and go to the next field
[notif_obj resignFirstResponder];
[[notif_obj nextKeyView] becomeFirstResponder]; // If you set the nextKeyView, otherwise use something like licenseFieldTwo here
}
else if (notif_obj == licenseFieldTwo)
{
// Repeat
}
// Repeat for as many fields as you have
}


I can't remember if the object of the notif is the textfield or the field editor, you would have to test that. If it is the field editor Erik's trick for getting the textfield will work.

It assumes that you set the nextKeyView on the textfields to be logical.
Also, I am assuming that different fields in your license string could have different formats. If not, you could generalize and remove the messy if chain. And probably get rid of your outlets to the fields.


I haven't tested this, but I think it should work.

Hope it helps!
Michael.


On 24-Aug-05, at 7:09 PM, Brad Peterson wrote:

Hi,

First, thank you. :)


if([fieldEditor
respondsToSelector:@selector(delegate)])

{
   field = [fieldEditor delegate];

}
if (field == txtPartialSN1)


Ta-da! That did it! :)



However, I think that is all unnecessary because I think you can set up your formatter to end editing when the correct number of digits are entered and you can set up the nextField to automatically move to the next field when editing ends.


Ok, fair enough. I do see the nextKeyView, and you're surely right. However, I don't see how to set it up so that the user is automatically forwarded when the max # of characters has been reached. For that matter, I'm not sure how to get the formatter to prohibit editing.


At the moment, I'm using the isPartialStringValid: method, but I don't know how I'd explicitly end editing other than to simply continue to trim any additional characters the user might try to type (which I already do).

It sounds like you had something more specific in
mind.

Thanks again!

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40marketcircle.com


This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: firstResponder and multiple NSTextFields
      • From: Michael Clark <email@hidden>
References: 
 >Re: firstResponder and multiple NSTextFields (From: Brad Peterson <email@hidden>)

  • Prev by Date: Re: UTF8 question.
  • Next by Date: Re: Catching application errors
  • Previous by thread: Re: firstResponder and multiple NSTextFields
  • Next by thread: Re: firstResponder and multiple NSTextFields
  • Index(es):
    • Date
    • Thread