Just like with Apples timer app, you can't select "0". You have to choose at least 1 hour or 1 minute. Here is how I'm formatting the textfield for the picker..
就像Apples计时器应用程序一样,您不能选择“0”。你必须选择至少1小时或1分钟。这是我如何格式化选择器的文本字段..
//Formats the textfield based on the pickers.
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
NSString *result = [feetArray objectAtIndex:[feetPicker selectedRowInComponent:0]];
result = [result stringByAppendingFormat:@"%@ft", [feetArray objectAtIndex:[feetPicker selectedRowInComponent:1]]];
result = [result stringByAppendingFormat:@" %@", [inchArray objectAtIndex:[inchesPicker selectedRowInComponent:0]]];
result = [result stringByAppendingFormat:@"%@", [inchArray objectAtIndex:[inchesPicker selectedRowInComponent:1]]];
result = [result stringByAppendingFormat:@" %@in", [fractionArray objectAtIndex:[fractionPicker selectedRowInComponent:0]]];
RiseTextField.text = result;
}
What I need to if they choose "0" all the way across, I want the foot to automatically go to 1 on the picker. I have 3 pickers in my view made as one. 2 components for feet, 2 components for inches then 1 component for fractions. so its displayed in the textfield like 10f 09 1/16in.
如果他们一直选择“0”我需要什么,我希望脚在选择器上自动转到1。在我看来,我有3个采摘者。 2个组件用于英尺,2个组件用于英寸,然后1个组件用于分数。因此它在文本字段中显示为10f 09 1 / 16in。
1 个解决方案
#1
1
Essentially what you want to do is this:(assuming that row 0 contains the zero values)
基本上你想要做的是:(假设第0行包含零值)
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
if (([feetPicker selectedRowInComponent:0] == 0)&&
([feetPicker selectedRowInComponent:1] == 0)&&
([inchesPicker selectedRowInComponent:0] == 0)&&
([inchesPicker selectedRowInComponent:1] == 0)&&
([fractionPicker selectedRowInComponent:0] == 0)){
// All values zero
[feetPicker selectRow:1
inComponent:1
animated:YES];
return;
}
// Handle valid value
}
On a side note consider using an NSMutableString
for result
. Then instead of creating a new NSString
every line you can just call [result appendFormat:@"....
to modify the one you have.
另外,请注意使用NSMutableString作为结果。然后,不是每行创建一个新的NSString,你可以调用[result appendFormat:@“....来修改你拥有的那个。
#1
1
Essentially what you want to do is this:(assuming that row 0 contains the zero values)
基本上你想要做的是:(假设第0行包含零值)
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
if (([feetPicker selectedRowInComponent:0] == 0)&&
([feetPicker selectedRowInComponent:1] == 0)&&
([inchesPicker selectedRowInComponent:0] == 0)&&
([inchesPicker selectedRowInComponent:1] == 0)&&
([fractionPicker selectedRowInComponent:0] == 0)){
// All values zero
[feetPicker selectRow:1
inComponent:1
animated:YES];
return;
}
// Handle valid value
}
On a side note consider using an NSMutableString
for result
. Then instead of creating a new NSString
every line you can just call [result appendFormat:@"....
to modify the one you have.
另外,请注意使用NSMutableString作为结果。然后,不是每行创建一个新的NSString,你可以调用[result appendFormat:@“....来修改你拥有的那个。