-(void)textFieldDidEndEditing:(UITextField *)textField
{
if(textField == self.nameField)
{
self.movie.name = self.nameField.text;
}
else if(textField == self.summaryField)
{
self.movie.summary = self.summaryField.text;
}
else if(textField == self.budgetField)
{
NSNumberFormatter *formatter = [[NSNumberFormatter alloc]init];
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
self.movie.budget = [formatter numberFromString:self.budgetField.text];
NSLog(@"%@",self.movie.budget);
[formatter release];
}
}
The Above code is from the Movie_LibraryEditorViewController.m file which is my second view in my project. In "self.movie.budget" it doesn't take the value, it takes as null. In the First View i have labels in which the text is displayed. Now "movie" object is of the class Movie_Library in which i 开发者_JAVA百科have overridden the following method.
-(id)initWithTitle:(NSString *)newname budget:(NSNumber *)newbudget summary:(NSString *)newsummary
{
self = [super init];
if(nil!=self)
{
self.name = newname;
self.budget = newbudget;
self.summary = newsummary;
}
return self;
}
Now my question is Why the Null value? Am i doing smmin wrong here?
You need to type the currency code if you use NSNumberFormatterCurrencyStyle
. Default code is "$". So, the string should look like this
[formatter numberFromString:@"$34"];
精彩评论