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 protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to