0

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..

//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.

Jason
  • 650
  • 2
  • 10
  • 33
  • Is this like there are two component in your picker one for feet and another for inches? and you don't want to allow 0 feet and 0 inches right? – iphonedev23 Jan 13 '12 at 05:18
  • Yes, 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. – Jason Jan 14 '12 at 16:16

1 Answers1

1

Essentially what you want to do is this:(assuming that row 0 contains the zero values)

-(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.

NJones
  • 27,139
  • 8
  • 70
  • 88
  • 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. That help the code make more sense? – Jason Jan 14 '12 at 16:23
  • Sorry, I guess I should have also said that I didn't want a value less than 1 foot to be allowed. If it's under a foot, the app crashes when calculating. – Jason Jan 14 '12 at 17:28
  • So it seems to work like this as needed. if (([feetPicker selectedRowInComponent:0] == 0)){ // All values zero [feetPicker selectRow:1 inComponent:1 animated:YES]; } – Jason Jan 14 '12 at 17:31
  • actually this was this fix: if (([feetPicker selectedRowInComponent:0] == 0 & [feetPicker selectedRowInComponent:1] == 0)){ // All values zero [feetPicker selectRow:1 inComponent:1 animated:YES]; } – Jason Jan 15 '12 at 00:45