好的,我查看了其他类似的问题,但我无法弄清楚为什么 NSNumber 与 UIText 字段不兼容。
我的.h
@property (weak, nonatomic) IBOutlet UITextField *initialBudget;
@property (weak, nonatomic) IBOutlet UITextField *expenses;
@property (weak, nonatomic) IBOutlet UITextField *timeSpent;
@property (weak, nonatomic) IBOutlet UITextField *incomePerHour;
这是我的计算
- (IBAction)calculateResults:(id)sender {
double budget = [initialBudget.text doubleValue ];
double expense = [expenses.text doubleValue];
double time = [timeSpent.text doubleValue];
double hourlyIncome = (budget - expense)/time;
NSNumber *resultNumber = [[NSNumber alloc] initWithDouble:hourlyIncome];
incomePerHour = resultNumber;
}
任何帮助都会很棒,谢谢