我现在有一点编码问题。我有一个带有 7 个不同选项的选择器,目前出于测试目的,我有一个标签,将显示选择器的所选值。
我遇到的问题是我的标签只显示整数,而不显示整个十进制数,有人可以帮助我,以便我可以获得选择器中所选项目的全部价值吗?
这是我的代码:
// returns the number of 'columns' to display.
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return [tempList count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [tempList objectAtIndex:row];
}
- (void)pickerView:(UIPickerView *)pickerView
didSelectRow:(NSInteger)row
inComponent:(NSInteger)component {
CGFloat chosenValue;
switch (row) {
case 0:
chosenValue = 0.0000373;
break;
case 1:
chosenValue = 0.0000273;
break;
case 2:
chosenValue = 0.0000233;
break;
case 3:
chosenValue = 0.0000204;
break;
case 4:
chosenValue = 0.0000179;
break;
case 5:
chosenValue = 0.0000169;
break;
case 6:
chosenValue = 0.0000142;
break;
default:
chosenValue = 0;
break;
}
NSNumberFormatter *formatter = [[NSNumberFormatter alloc]init];
formatter.numberStyle = NSNumberFormatterDecimalStyle;
self.testLabel.text = [formatter stringFromNumber:@(chosenValue)];
}