• 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: Frederick Cheung <email@hidden>
  • Date: Tue, 14 Sep 2004 17:13:48 +0200


On 14 Sep 2004, at 16:35, j o a r wrote:

Store a copy of the string every time you get the notification. If the string changes to a length > 32, simply restore the previous string.


a good suggestion.
On 2004-09-14, at 16.00, Peter Karlsson wrote:

I have the following code to limit the length of the string I type in my textfield:

-(void)controlTextDidChange:(id)sender
{
// 32 character limit on my textfield
if ([[myTextfieldOutlet stringValue] length] > 32)
{
[myTextfieldOutlet setStringValue: [NSString stringWithString:[[myTextfieldOutlet stringValue] substringToIndex: 32]]];
}
}

I can only type 32 characters, wonderful but...

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.

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?

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.

Be careful with what you do. Depending on the input method, characters do not necessarily arrive in your text field one by one. Also it is a bad idea (tm) to truncate a unicode string at an arbitrary index or delete some arbitrary range. You could get unexpected results or even an invalid string.

Fred

_______________________________________________
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: Andreas Mayer <email@hidden>
References: 
 >controlTextDidChange, backspace possible? (From: "Peter Karlsson" <email@hidden>)
 >Re: controlTextDidChange, backspace possible? (From: j o a r <email@hidden>)

  • Prev by Date: Country codes vs. Language codes
  • Next by Date: Re: controlTextDidChange, backspace possible?
  • Previous by thread: Re: controlTextDidChange, backspace possible?
  • Next by thread: Re: controlTextDidChange, backspace possible?
  • Index(es):
    • Date
    • Thread