在我的项目中,想先以华氏度显示天气,然后如果用户想要点击转换,则需要以摄氏度显示天气。我的代码是
NSNumber *metric = [[NSUserDefaults standardUserDefaults] objectForKey:@"metric"];
NSLog(@"Metric is %@", metric);
CGFloat aFloat = [speed floatValue];
CGFloat tFloat = [temperature floatValue];
CGFloat tempFloat = (tFloat-30)/2;
NSNumber * p_Number = [NSNumber numberWithFloat:tempFloat];
//Convert mph to kmph
if ([metric boolValue]) {
[windValueLabel setText:[NSString stringWithFormat:@"%.2f kmph", aFloat * 1.6] ];
temperatureLabel.text = [NSString stringWithFormat:@"%@", p_Number];
}
else{
[windValueLabel setText:[NSString stringWithFormat:@"%.2f mph", aFloat / 1.6]];
temperatureLabel.text = [NSString stringWithFormat:@"%@", temperature];
}
当您启动应用程序时,它的工作和显示温度为华氏温度,但在摄氏温度下崩溃……这是当前的转换。帮帮我,伙计们