• 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: Stripping newlines/blanks when pasting on an NSTextField
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Stripping newlines/blanks when pasting on an NSTextField


  • Subject: Re: Stripping newlines/blanks when pasting on an NSTextField
  • From: Chris Suter <email@hidden>
  • Date: Sun, 29 Oct 2006 10:58:44 +1100

Hi,

Unfortunately, due to bugs with the framework, you'll get an exception if you try and undo.

I tried this a couple of weeks back. I've reported it to Apple.

If anyone knows any workaround, I'd like to know.

- Chris

On 29/10/2006, at 9:59 AM, Michele Balistreri wrote:

Thank you for your help. In the end i just used a formatter also implementing isPartialString.. to be called at each keypress

- (NSString *)stringForObjectValue:(id)anObject
{
return [[(NSString *)anObject componentsSeparatedByString:@"\n"] componentsJoinedByString:@""];


}

- (BOOL)getObjectValue:(id *)anObject forString:(NSString *)string errorDescription:(NSString **)error
{
*anObject = [[(NSString *)string componentsSeparatedByString:@"\n"] componentsJoinedByString:@""];
return YES;
}


- (BOOL)isPartialStringValid:(NSString *)partialString newEditingString:(NSString **)newString errorDescription:(NSString **)error
{
*newString = [[(NSString *)partialString componentsSeparatedByString:@"\n"] componentsJoinedByString:@""];
return NO;
}


This is the code, maybe not the best way to strip white characters, but trimming is not enough for me unfortunately. Indeed if someone knows a better way (maybe a little more flexible), please advice.

Regards,
Michele Balistreri
brik. Lead programmer.



Il giorno 29/ott/06, alle ore 00:51, I. Savant ha scritto:

On Oct 28, 2006, at 6:05 PM, Michele Balistreri wrote:
Hi, thank you for your help, i know how to remove characters from a string, my problem was giving them instant feedback of what has been done, say they paste 2 lines, they should be directly displayed as one in the field. That is possible only with formatters, or there are some special options of NSTextField?

Since you said removing characters from a string isn't the problem, I'll leave that part alone and address the 'immediate formatting' part. Sorry for the confusion. ;-)


Just having a filtering formatter isn't enough since the input isn't formatted until editing is done. A simple approach would be to use the -controlTextDidChange: delegate method to force the formatting by calling -validateEditing on the text field in question when the text changes:

- (void)controlTextDidChange:(NSNotification *)aNotification
{
    [[aNotification object] validateEditing];
}

This wouldn't work with NSNumberFormatter or NSDateFormatter since rejected input returns an empty string, so nothing appears to have happened but a system beep. Our filtering formatter will always return a string, so that shouldn't be a problem here.

--
I.S.




_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
systems.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
References: 
 >Stripping newlines/blanks when pasting on an NSTextField (From: Michele Balistreri <email@hidden>)
 >Re: Stripping newlines/blanks when pasting on an NSTextField (From: Rosyna <email@hidden>)
 >Re: Stripping newlines/blanks when pasting on an NSTextField (From: "I. Savant" <email@hidden>)
 >Re: Stripping newlines/blanks when pasting on an NSTextField (From: Rosyna <email@hidden>)
 >Re: Stripping newlines/blanks when pasting on an NSTextField (From: "I. Savant" <email@hidden>)
 >Re: Stripping newlines/blanks when pasting on an NSTextField (From: Rosyna <email@hidden>)
 >Re: Stripping newlines/blanks when pasting on an NSTextField (From: Michele Balistreri <email@hidden>)
 >Re: Stripping newlines/blanks when pasting on an NSTextField (From: "I. Savant" <email@hidden>)
 >Re: Stripping newlines/blanks when pasting on an NSTextField (From: Michele Balistreri <email@hidden>)

  • Prev by Date: Re: Stripping newlines/blanks when pasting on an NSTextField
  • Next by Date: drawRect troubles
  • Previous by thread: Re: Stripping newlines/blanks when pasting on an NSTextField
  • Next by thread: Re: Stripping newlines/blanks when pasting on an NSTextField
  • Index(es):
    • Date
    • Thread