Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1114087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:57:24+00:00 2026-05-17T02:57:24+00:00

I have a UIPicker with 3 components containing numeric values, this allows the user

  • 0

I have a UIPicker with 3 components containing numeric values, this allows the user to set the time in hh:mm:ss format. If I select the hour from the first component my UITextField looks like this: 10:(null):(null). The (null) can be removed when the user selects the appropriate mm and ss. But if the user just wants to enter 10 hours, I want the other values to be 00 instead of (null), without the user having to physically move the picker components.

Anyone have any ideas on this ?

Some code below, this question is related to the timePicker.

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if([pickerView isEqual: routePicker])
    {
        route.text = [[routeArray objectAtIndex:0] valueForKey:@"route_name"];
        return [[routeArray objectAtIndex:row] valueForKey:@"route_name"];
    }
    else if([pickerView isEqual: activityPicker])
    {
        activity.text = [activityArray objectAtIndex:0];
        return [activityArray objectAtIndex:row];
    }
    else if([pickerView isEqual: intensityPicker])
    {
        if ([intensityArray objectAtIndex:row]==@"Low")
            numberIntensity=2;
        else if ([intensityArray objectAtIndex:row]==@"Low-Medium")
            numberIntensity=3.5;
        else if ([intensityArray objectAtIndex:row]==@"Medium")
            numberIntensity=5;
        else if ([intensityArray objectAtIndex:row]==@"Medium-High")
            numberIntensity=6.5;
        else if ([intensityArray objectAtIndex:row]==@"High")
            numberIntensity=8;
        else numberIntensity=0;

        intensity.text = [intensityArray objectAtIndex:0];
        return [intensityArray objectAtIndex:row];
    }
    else if([pickerView isEqual: timePicker])
    {
        switch (component)
        {
            case 0:
                return [hourArray objectAtIndex:row];
                break;
            case 1:
                return [minuteArray objectAtIndex:row];
                break;
            case 2:
                return [secondArray objectAtIndex:row];
                break;
            default:
                return 0;
                break;
        }
    }
    else if([pickerView isEqual: distancePicker])
    {
        switch (component)
        {
            case 0:
                return [distance1Array objectAtIndex:row];
                break;
            case 1:
                return [distance2Array objectAtIndex:row];
                break;
            default:
                return 0;
                break;
        }
    }   
    else 
    {
        return 0;
    }
}



-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if([pickerView isEqual: routePicker])
    {
        route.text = [[routeArray objectAtIndex:row] valueForKey:@"route_name"];
    } 
    else if([pickerView isEqual: timePicker])
    {
        if (component == 0)
        {
            selectedHour = [hourArray objectAtIndex:row];
        } 
        else if (component == 1)
        {
            selectedMinute = [minuteArray objectAtIndex:row];
        } 
        else if (component == 2)
        {
            selectedSecond = [secondArray objectAtIndex:row];
        }
        time.text = [NSString stringWithFormat:@"%@:%@:%@", selectedHour, selectedMinute, selectedSecond];
    }
    else if([pickerView isEqual: distancePicker])
    {
        if (component == 0)
        {
            selectedDistance1 = [distance1Array objectAtIndex:row];
        } 
        else if (component == 1)
        {
            selectedDistance2 = [minuteArray objectAtIndex:row];
        } 
        distance.text = [NSString stringWithFormat:@"%@.%@", selectedDistance1, selectedDistance2];
    }
    else if([pickerView isEqual: activityPicker])
    {
        activity.text = [activityArray objectAtIndex:row];
    }
    else if([pickerView isEqual: intensityPicker])
    {
        intensity.text = [intensityArray objectAtIndex:row];
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T02:57:25+00:00Added an answer on May 17, 2026 at 2:57 am

    I think this line:

    time.text = [NSString stringWithFormat:@"%@:%@:%@", selectedHour, selectedMinute, selectedSecond];
    

    could be changed to:

    time.text = [NSString stringWithFormat:@"%@:%@:%@",
                 (selectedHour ? selectedHour : @"00"),
                 (selectedMinute ? selectedMinute : @"00"),
                 (selectedSecond ? selectedSecond : @"00")];
    

    This assumes that selectedHour, selectedMinute and selectedSecond are all initially nil outside of this code. I am away from my mac, so I haven’t tested this.

    Alternatively, you could initialize selectedHour, selectedMinute and selectedSecond to @"00".

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dependent UIPicker that loads the values into its two components from
I have a UIPicker where the user inputs a specified time (i.e. 13:00, 13:01,
have written this little class, which generates a UUID every time an object of
I have the UIPicker setup with multiple components and a button below it. Depending
I have a UIPicker view containing 4 columns with the same array of 6
I have set up this combo box and it works great. Now I have
I have a table with a list of employee data. User can select the
I have a UIPicker view with multiple components/columns. Is it possible for the components
I have 1 UIPicker with 5 components, all numbers 1-9. I just want all
i currently have a uipicker with two components. The first contains images and works

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.