所以這個問題讓我困惑太久。我有一個UIAlertView
其中有一個textField
,我需要textField
的值作爲NSNumber
。但是我嘗試的每件事都給了我隨機的數字。任何幫助將非常感激。NSString到NSNumber
int i = [[alertView textFieldAtIndex:0].text intValue];
NSNumber *number = [NSNumber numberWithInt:[[alertView textFieldAtIndex:0].text integerValue]];
int number = [[dict objectForKey:@"integer"] intValue];
NSLog(@"text = %@", [alertView textFieldAtIndex:0].text);
NSString *alertText = [alertView textFieldAtIndex:0].text;
NSNumberFormatter * f = [[NSNumberFormatter alloc] init];
[f setNumberStyle:NSNumberFormatterNoStyle];
NSNumber * myNumber = [f numberFromString:[alertView textFieldAtIndex:0].text];
NSNumber *number = @([alertText intValue]);
NSString *string = @"54";
NSNumber *number = @([string intValue]);
NSLog(@"here we are: %i", number);
相關:http://stackoverflow.com/questions/1448804/how-to-convert-an-nsstring-into-an-nsnumber –
我看到之前問。但是當我運行這些代碼時,我得到了:'159348080' – Andrew
請發佈您的代碼,在這裏您可以從文本文件中獲取價值 –