如何更新ios中的文本字段值

时间:2012-09-04 12:48:54

标签: iphone ios ios5 uitextfield

我使用NSNumberFormatter有一个像100,000这样的文本字段值,现在我想编辑我的文本字段,再添加一个0。在我想要像1,000,000之类的文本之后更改但我的文本字段值更改为0

3 个答案:

答案 0 :(得分:0)

尝试这样,

 int x=[textfield.text intValue];

你可以得到正确的价值......

答案 1 :(得分:0)

试试这段代码。它可能会帮助你

  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]];

答案 2 :(得分:0)

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]];

试试这个