使用我的UISlider,如果我的值'tipPercentage'达到10或更多,标签'costWithTipLabel'将被设置回textField的'costWithoutTip'值,从10%的小费增加开始。
如果您能查看我的代码并让我知道导致此问题的问题,我将非常感激。
先谢谢。
- (IBAction)aSliderChanged:(id)sender {
UISlider *slider = (UISlider *)sender;
if (slider == tipslide) {
NSString *tip = [NSString stringWithFormat:@"%.f", slider.value * 100];
float tipPercentage = [tip floatValue];
NSString *multiplier = [NSString stringWithFormat:@"1.%.f", tipPercentage];
[costWithTipLabel setText:[NSString stringWithFormat:@"%.2f", [[costWithoutTip text] floatValue] * [multiplier floatValue]]];
[tipTextLabel setText:[[NSString stringWithFormat:@"Tip (%.f", slider.value *100]stringByAppendingString:@"%):"]];
}
else if (slider == peopleslide) {
NSString *p = [NSString stringWithFormat:@"%.f", slider.value*10];
float numOfPeople = [p floatValue];
[numberOfPeopleTextLabel setText:[NSString stringWithFormat:@"Each (%.f):", numOfPeople]];
[numberOfPeopleLabel setText:[NSString stringWithFormat:@"%.2f", [[costWithTipLabel text] floatValue]/numOfPeople]];
}
[totalBillCost setText:[NSString stringWithFormat:@"%.2f", [[costWithTipLabel text] floatValue]]];
}
答案 0 :(得分:0)
我希望它与字符串的意外格式有关。我建议你将stringWithFormat赋值分解为多个简单(非嵌套)语句,然后使用尽可能通用的格式(%f)NSLog值。然后你应该能够找出问题所在。