【发布时间】:2011-05-09 10:40:26
【问题描述】:
我正在开发一个带有从底部滑动的选择器视图(如操作表)的应用程序。我需要转换 3 个单位(升、美制加仑和英制加仑)。该值取自文本字段,但我不知道如何告诉编译器从哪个单元开始。 (即...用户在文本字段中插入值,但如果他更改单位(usg 或 ig),则文本字段中的值会相应更改。
这是数组:
NSMutableArray *weightArray = [[NSMutableArray alloc] initWithObjects:@"", @"Ltr",@"Usg",@"Ig",
nil];
self.weightPickerViewArray = weightArray;
[weightArray release];`
这是选择器:
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
if (row == 1) {
labelVolume.text = [weightPickerViewArray objectAtIndex:row];
//more code here....
}else if (row == 2){
labelVolume.text = [weightPickerViewArray objectAtIndex:row];
//more code here....
}else if (row == 3){
labelVolume.text = [weightPickerViewArray objectAtIndex:row];
//more code here....
} 如何告诉编译器选择之前的值是什么?
【问题讨论】:
-
嗯,不清楚..至少对我来说..:(
-
@mattia 还是不明白
-
好的...让我再试一次。默认值为升。例如,用户在文本字段中插入 1000 升。如果用户按下“更改单位”按钮,选择器或操作表将从底部滑出,提供 3 个选项:升、美制加仑和英制加仑。当用户选择 us 加仑时,文本字段中的值从 1000 L 变为 264.17 usg。
-
@mattia ok now it is clear,so what is the problem ,what you want to do when the picker slides up?
-
when the picker slides up the user can select 3 different units: Litres, Us gallons or Imperial gallons.选择其中一个单位时,有一个标签(在文本字段旁边),该标签将变为LTR,USG或IG。到目前为止,一切都很完美。我还想将文本字段中的值转换为用户选择的单位。我要发布我的代码....;-)
标签: iphone objective-c ios4