0

我有三个标签接收来自三个的输出UISliders。当触摸分段控件时,计算结果并将其放置在第四个标签中。

如果更改滑块值之一而不再次触摸分段控件,如何更新结果?

4

2 回答 2

1

首先,为您的滑块更改值添加一个事件:

[mySlider addTarget:self 
             action:@selector(sliderValueChanged:) 
   forControlEvents:UIControlEventValueChanged];

您需要为每个滑块执行此操作。

在您的sliderValueChanged:功能中:

- (void)sliderValueChanged:(id)sender {
    [self calculateResult];
}

calculateResult您可以在其中进行计算并设置结果框。

如果您需要确保您的分段控件首先处于某种状态,只需添加一个if子句sliderValueChanged:

- (void)sliderValueChanged:(id)sender {
    if ([mySegmentedControl selectedSegmentIndex] == 1) {
        [self calculateResult];
    }
}
于 2012-06-22T17:51:29.307 回答
0

我想出了一些使用mopsled 的答案的东西:

if (UIControlEventValueChanged && mySeg.selectedSegmentIndex == 0) {
    float floatResult = [f3.text floatValue]-[f2.text floatValue];
    float coldFactor = [fcold.text floatValue]*floatResult;
    float result = [f1.text floatValue]+coldFactor;

    NSString *tpResult = [[NSString alloc] initWithFormat:@"%.0f",result];
    f4Result.text = tpResult;             
}
于 2012-07-14T22:31:12.257 回答