how to update the textfield value in ios [closed]

2019-09-23 02:12发布

问题:

I have one textfield value like 100,000 using NSNumberFormatter, now I want to edit my textfield, to add one more 0 . After I Want to Change like the text like 1,000,000 but my textfield value is changed as 0

回答1:

numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setNumberStyle: NSNumberFormatterNoStyle];
[numberFormatter setGroupingSize:3];
[numberFormatter setGroupingSeparator:@","];
[numberFormatter setUsesGroupingSeparator:YES];
number= [NSNumber numberWithInt:[textFieldString intValue]];
NSString *numberString = [NSString stringWithFormat:@"$%@",[numberFormatter stringForObjectValue:number]];

try this



回答2:

try like this,

 int x=[textfield.text intValue];

you can get the correct value.....



回答3:

Try this code. It may help you

  NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
    [numberFormatter setFormat:@"#,###"];
    NSNumber *averageResponseTime = [NSNumber numberWithInt:[textfield.text intValue]];

//If you print text 


 [NSString stringWithFormat: @"%@ms",[numberFormatter stringForObjectValue:averageResponseTime]];