【问题标题】:Help with UISlider帮助 UISlider
【发布时间】: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


    【解决方案1】:

    我认为这与字符串的意外格式有关。我建议您将您的 stringWithFormat 分配分解为多个简单(非嵌套)语句,然后使用尽可能通用的格式 (%f) NSLog 您的值。然后你应该能够找到问题所在。

    【讨论】:

      猜你喜欢
      • 2015-10-10
      • 2018-12-21
      • 2011-06-20
      • 2011-07-28
      • 2011-10-04
      • 2011-08-03
      • 2011-11-27
      • 1970-01-01
      • 2011-08-16
      相关资源
      最近更新 更多