爆出錯誤:
Incompatible pointer types assigning to 'UITextfield *_strong' from 'NSNumber *_strong
代碼:
.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;
};
問題出在這裡
incomePerHour = resultNumber;
incomePerHour為UITextField 類型,而resultNumber為 NSNumber 類型。這兩個不著邊的對象怎可相互轉換?
改成
incomePerHour.text=[NSString stringWithFormat:@"%f",hourlyIncome];