我有一个带有 textField 的 inputView 的 UIPickerView 显示。我已将pickerView 分成两列。一种是整数 50-500。另一个是 0.25,0.50,0.75。我希望他们能够选择整数,然后选择另一列的数字的小数部分。我不知道如何显示“完整”号码。当我移动第二列时,它只是将其注册为移动第一列并更改整数。我希望用户能够选择一个整数、数字的小数部分、点击完成,并且 textField 显示一个格式为“100.25”的数字或他们选择的任何数字。我已经对完成按钮进行了编码......并且整个数字仅以格式显示,即“100”。
谢谢!
更新!!!代码!!!!
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent: (NSInteger)component{
if ([pickerView isEqual:weightPickerView]) {
weightField.text = [NSString stringWithFormat:@"%d.%d",[weightPickerArray objectAtIndex:row], [weightPickerArray2 objectAtIndex:row]];
-(void)populateWeightPickerArray{
weightPickerArray = [[NSMutableArray alloc] init];
for (int weight = 50; weight <=500; weight++) {
NSString *weightString = [NSString stringWithFormat:@"%d%",weight];
[weightPickerArray addObject:weightString];
}
}
-(void)populateWeightPickerArray2{
weightPickerArray2 = [[NSMutableArray alloc] init];
[weightPickerArray2 addObject:@"0.25"];
[weightPickerArray2 addObject:@"0.50"];
[weightPickerArray2 addObject:@"0.75"];
}
所以我希望用户选择他们的体重——例如第一列为 100,第二列为 0.25。然后我希望文本字段显示 100.25...
更新 2!更改了代码,现在我收到一个错误..
[会话开始于 2012-08-03 10:39:39 -0500。] 2012-08-03 10:39:45.656 CalorieAppFinal[1088:207] -[NSCFNumber isEqualToString:]:无法识别的选择器发送到实例 0x4b336c0 2012-08 -03 10:39:45.661 CalorieAppFinal[1088:207] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[NSCFNumber isEqualToString:]:无法识别的选择器发送到实例 0x4b336c0”*在第一次抛出时调用堆栈
这是我如何初始化我的 weightPicker
-(IBAction)weightFieldDidBeginEditing{
weightPickerView = [[UIPickerView alloc] init];
weightField.inputView = weightPickerView;
weightPickerView.showsSelectionIndicator = YES;
weightPickerView.delegate = self;
weightPickerView.dataSource = self;
[weightPickerView release];
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
if ([pickerView isEqual:weightPickerView]) {
int valOne = [[weightPickerArray objectAtIndex:row] intValue];
CGFloat valTwo = [[weightPickerArray2 objectAtIndex:row] floatValue];
weightField.text = [NSString stringWithFormat:@"%d.%.2f",valOne, valTwo];
}
-(void)populateWeightPickerArray{
weightPickerArray = [[NSMutableArray alloc] init];
for (int weight = 50; weight <=500; weight++) {
[weightPickerArray addObject:[NSNumber numberWithInt:weight]];
}
}
-(void)populateWeightPickerArray2{
weightPickerArray2 = [[NSMutableArray alloc] init];
[weightPickerArray2 addObject:[NSNumber numberWithFloat:0.25f]];
[weightPickerArray2 addObject:[NSNumber numberWithFloat:0.50f]];
[weightPickerArray2 addObject:[NSNumber numberWithFloat:0.75f]];
}