• 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: controlTextDidChange, backspace possible?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: controlTextDidChange, backspace possible?


  • Subject: Re: controlTextDidChange, backspace possible?
  • From: Daniel Todd Currie <email@hidden>
  • Date: Tue, 14 Sep 2004 11:27:26 -0700

In my humble opinion, this is a textbook example of where NSFormatters should be used. Apple's documentation on NSFormatters reads:

"NSFormatter is an abstract class that declares an interface for objects that create, interpret, and validate the textual representation of cell contents."

Isn't this what we are looking for, a way to validate the user's input? I posted an NSFormatter subclass about a month ago, here's a link in the archives:

http://www.cocoabuilder.com/archive/message/2004/8/11/114277

This link also has some nice example source, including an NSFormatter subclass:

http://www.lumacode.com/simon/developer.html

Hope this helps.

-- DTC


On 2004 Sep 14, at 09:02, Peter Karlsson wrote:

The idea to make a formatter is great, but I don't have that skill. I am just a newbee. But if some of the pros here want to do it I would be very happy. There is a date formatter and a number formatter in IB. I think there should be a third one as well that solves this type of problems once for all.

Peter


From: "M. Uli Kusterer" <email@hidden>
To: "Peter Karlsson" <email@hidden>, email@hidden
Subject: Re: controlTextDidChange, backspace possible?
Date: Tue, 14 Sep 2004 17:07:34 +0200

At 14:00 Uhr +0000 14.09.2004, Peter Karlsson wrote:
If I have the cursor in the middle of the string the last character of the string will dissapear for every new character I type.

Yes, that's exactly what your code does, as it doesn't take into account the selection.


My idea is to make a backspace so the latest character will not be typed if the string is already 32 characters in length. Is this possible to do, or is there better solutions?

Have you looked at NSFormatter? It looks like writing an NSFormatter of your own will let you do just what you want.


The point is, I do not want anything to happen at all if I type and the string is already 32 characters in length. So I must find a way to delete the latest character typed regardless of the position in the string.

If NSFormatter (which would be reusable and looks like the "recommended way") doesn't let you do what you want, another option might be to replace the field editor in your window with one where you've overridden the keyDown: method. Then you could check that there. Or switch to an NSTextView subclass instead of an NSTextField.


But NSFormatter sounds like it will be a lot less painful in the long run. And I'm sure lots of people here would be pleased if you put up such a formatter for download somewhere. Length-limiting text entry fields is a common enough problem that I don't get why there isn't a solution built in already.
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de

_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963


_______________________________________________
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



_______________________________________________ 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: controlTextDidChange, backspace possible?
      • From: "M. Uli Kusterer" <email@hidden>
References: 
 >Re: controlTextDidChange, backspace possible? (From: "Peter Karlsson" <email@hidden>)

  • Prev by Date: Re: custom NSView problem
  • Next by Date: Re: Home and end keys and NSTableView, not handled automatically?
  • Previous by thread: Re: controlTextDidChange, backspace possible?
  • Next by thread: Re: controlTextDidChange, backspace possible?
  • Index(es):
    • Date
    • Thread