Iphone 有没有办法在UIPickerView中显示1/2而不是.5?
是否可以在UI PickerView中显示1/2而不是.5 这是我当前使用的代码:Iphone 有没有办法在UIPickerView中显示1/2而不是.5?,iphone,objective-c,cocoa-touch,Iphone,Objective C,Cocoa Touch,是否可以在UI PickerView中显示1/2而不是.5 这是我当前使用的代码: pickerArray = [[NSMutableArray alloc] initWithCapacity:700]; for ( float i = 0.0 ; i <= 1000.0 ; i = i + 2.5) { //[pickerArray addObject:[NSString stringWithFormat:@"%.1f", i]] [pickerArray addObje
pickerArray = [[NSMutableArray alloc] initWithCapacity:700];
for ( float i = 0.0 ; i <= 1000.0 ; i = i + 2.5)
{
//[pickerArray addObject:[NSString stringWithFormat:@"%.1f", i]]
[pickerArray addObject:[NSNumber numberWithFloat:i];
}
float weight = [[pickerArray objectAtIndex:row] floatValue];
label.text = [NSString stringWithFormat:@"%.1f", weight];
pickerArray=[[NSMutableArray alloc]initWithCapacity:700];
对于(float i=0.0;i我建议这样做:
NSMutableArray *array = [[NSMutableArray alloc] init];
for (int i=0;i<100;i++) {
float value = (float)i*2.5;
if (i % 2) {
[array addObject:[NSString stringWithFormat:@"%d %@",(int)value,@"1/2"]];
} else {
[array addObject:[NSString stringWithFormat:@"%d",(int)value]];
}
}
label.text = [array objectAtIndex:row];
按如下方式更新标签:
NSMutableArray *array = [[NSMutableArray alloc] init];
for (int i=0;i<100;i++) {
float value = (float)i*2.5;
if (i % 2) {
[array addObject:[NSString stringWithFormat:@"%d %@",(int)value,@"1/2"]];
} else {
[array addObject:[NSString stringWithFormat:@"%d",(int)value]];
}
}
label.text = [array objectAtIndex:row];