Re: UITextField formatting for IP Address
Re: UITextField formatting for IP Address
- Subject: Re: UITextField formatting for IP Address
- From: Andrew Farmer <email@hidden>
- Date: Fri, 16 Oct 2009 21:46:41 -0700
On 16 Oct 2009, at 17:54, Alex Kac wrote:
Here is my code, btw. It works OK, but it still has the issue of
moving the cursor to the end. Perhaps there is no way to do this on
the iPhone - I just don't want to bang my head for hours.
- (void)formatForIP:(UITextField*)textField string:(NSString*)string
{
long long ip = [[string stringByReplacingOccurrencesOfString:@"."
withString:@""] longLongValue];
NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc]
init];
[numberFormatter setNumberStyle:NSNumberFormatterNoStyle];
[numberFormatter setPositiveFormat:@"###,###,###,###"];
[numberFormatter setGroupingSize:3];
[numberFormatter setSecondaryGroupingSize:3];
[numberFormatter setGroupingSeparator:@"."];
[numberFormatter setUsesGroupingSeparator:YES];
textField.text = [numberFormatter stringFromNumber:[NSNumber
numberWithLongLong:ip]];
[numberFormatter release];
}
This isn't a valid approach to formatting IP addresses - it considers
"12.34.56.78" to be equal to "12.345.678", which isn't even a valid
address, let alone equivalent.
_______________________________________________
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