【发布时间】:2011-04-16 14:54:24
【问题描述】:
使用我的 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]]];
}
【问题讨论】:
标签: iphone objective-c xcode uislider number-formatting