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 7436847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:18:19+00:00 2026-05-29T10:18:19+00:00

I have a picker view where the user is entering a time. When they

  • 0

I have a picker view where the user is entering a time. When they scroll down to hour 23, I want hour zero to appear as the next item, and the sequence to re-start. How can I achieve this?

Here is my current picker view data source:

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 3; 
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
  NSArray *sectionContents = [[self dataForDatapickerRows] objectAtIndex:component];    
  NSInteger rows = [sectionContents count];     
  NSLog(@"component %d rows is: %d",component,rows);    
  return rows;  
}
- (NSString *)pickerView:(UIPickerView *)pickerView
             titleForRow:(NSInteger)row
            forComponent:(NSInteger)component {
  self.dataPickerInstance.backgroundColor=[UIColor whiteColor];       
  return ([[[self dataForDatapickerRows ]objectAtIndex:component] objectAtIndex:row]);
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    if(component==0)
    {
      [self setHou:(NSInteger*)[[[self dataForDatapickerRows ]objectAtIndex:component] objectAtIndex:row]];
    }
    else if(component==1)
    {
      [self setMinut:(NSInteger*)[[[self dataForDatapickerRows ]objectAtIndex:component] objectAtIndex:row]];
    }
    else if(component==2)
    {
      [self setSecon:(NSInteger*)[[[self dataForDatapickerRows ]objectAtIndex:component] objectAtIndex:row]];
    }

    NSLog(@"%@",[[[self dataForDatapickerRows ]objectAtIndex:component] objectAtIndex:row]); 
}


- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
    UILabel* tView = (UILabel*)view;

    if (!tView){
        tView = [[UILabel alloc] init];
        [tView setFrame:CGRectMake(0, 0, 90,60)];
        tView.self.textColor=[UIColor whiteColor];
        tView.minimumFontSize = 80;
        tView.textAlignment=UITextAlignmentCenter;
        tView.adjustsFontSizeToFitWidth = YES;
        tView.autoresizesSubviews=YES;
        tView.font = [UIFont boldSystemFontOfSize:40];
        tView.backgroundColor = [UIColor blackColor];


        //tView.highlightedTextColor=[UIColor greenColor];
        // factLabel.frame = CGRectMake(factLabel.frame.origin.x, factLabel.frame.origin.y, factLabel.frame.size.width, lLabelSIze.height);
        //
        // Setup label properties - frame, font, colors etc
    }   // Fill the label text here
     tView.text=[[[self dataForDatapickerRows ]objectAtIndex:component] objectAtIndex:row];   

   return tView; 
}

enter image description here

  • 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-29T10:18:21+00:00Added an answer on May 29, 2026 at 10:18 am

    I have a custom time picker (UIPickerView), for which the delegate looks like this:

    -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
        return 4; // it's with am/pm in my case
    }
    -(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
        /// 18000 is divisible with 12, 24 (for the hour) and 60 (for the minutes and seconds)
        /// it can still get to the end.. but will need a lot of scrolling
        /// I set the initial value between 9000 and 9060
        if (component==0) { // hour
            return 18000;
        }
        if (component==3) { // am/pm
            return [_datasource count];
        }
          // seconds and minutes - could use 45000 so it repeats the same number of time as the hours
        return 18000;
    }
    -(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
        if (component==3) { // am/pm
            return [_datasource objectAtIndex:row];
        }
        if (component==0) { // hour
            return [NSString stringWithFormat:@"%d", row%12];
        }
        return [NSString stringWithFormat:@"%02d", row%60];
    }
    -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
        if (component==3) { // am/pm
            if (row==0&&_h>11) {
                _h-=12;
            }
            if (row==1&_h<12) {
                _h+=12;
            }
        }
        else if(component==0){
            _h=row%12;
            if ([self selectedRowInComponent:3]==1) { // handle am/pm
                _h+=12;
            }
        }
        else if(component==1){
            _m=row%60;
        }
        else if(component==2){
            _s=row%60;
        }
    }
    -(CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component{
        // set the size for components
        if (component<3) {
            return 50;
        }
        return 70;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with search form. I use date-time picker for user to
I want to have user select between two different buttons on a view, If
I have a picker view that has a list of numbers to pick from.
I have picker controls on a single view with two outlets for each. When
I have a date picker library written for MooTools that I want to port
I have a picker View in one xib file, and a map View in
I have a picker that prompts the user to choose a gender and an
I have a detail view with several textfields, next to one of them i
I am making a color picker. I have the following code: View controller.h: @interface
So I'd like to have a user select a contact using the People Picker

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.