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

Re: Textfield


  • Subject: Re: Textfield
  • From: John Stiles <email@hidden>
  • Date: Sun, 2 Dec 2007 08:56:50 -0800

Long ago I had a Carbon app which did the five-text-fields thing to enter serial numbers.
When I ported it to Cocoa, I changed it to automatically insert hyphens in the text as the user typed.
This was actually a lot easier for several reasons:
- it looked more like the key displayed in email/on the CD case
- no need to handle quirky things like "if the user clicks in an empty text field on the right and presses delete, where does the insertion point go?"
- the user can use the arrow keys to move around freely in the text field
- the user can click in the middle of a mostly-completed key, start typing, and it will "do the right thing" (insert letters, reflowing all the hyphens as appropriate)


Basically, any time the contents of the text field change, all you do is:
- get the string and insertion point location
- for the next 3 steps, update the insertion point location any time you add or remove characters in front of it:
- remove all the hyphens
- do any cleanup (capitalize, strip bad characters)
- reinsert the hyphens
- finally, replace the string and place the insertion point back into it


On Dec 2, 2007, at 7:29 AM, I. Savant wrote:

I have a window with 5 textfield to enter a serial number of 5x5 characters.
When I entrer 5 characters in a textfield, I want that the cursor goes automatically in the next textfields.

Why not just use one text field and your own NSFormatter to keep it formatted?


  Otherwise, you can respond to each field's -textDidChange: ...

--
I.S.


_______________________________________________

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:
40blizzard.com


This email sent to email@hidden

_______________________________________________

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: 
 >Textfield (From: Eric PETIT <email@hidden>)
 >Re: Textfield (From: "I. Savant" <email@hidden>)

  • Prev by Date: Re: Multiple applications, one NSUserDefaults object?
  • Next by Date: Re: ImageKit + GC = nogo? (or better... how :D)
  • Previous by thread: Re: Textfield
  • Next by thread: Re: Textfield
  • Index(es):
    • Date
    • Thread