How to make UIPickerWheel Add A Row Each Day

Discussion in 'iOS Programming' started by newtoiphonesdk, Jan 3, 2013.

  1. newtoiphonesdk macrumors 6502a

    Joined:
    Jul 30, 2010
    #1
    In my app, I would like to determine what day of the year it is, and then show a uipickerwheel that has a row for each day (not month or day, just 1, 2, 365). I use

    Code:
     NSCalendar *currentCalendar = [NSCalendar currentCalendar];
        NSDate *today = [NSDate date];
        NSInteger dc = [currentCalendar  ordinalityOfUnit:NSDayCalendarUnit
                                                   inUnit:NSYearCalendarUnit
                                                  forDate:today];
    to get the current number, but am unsure how to setup the uipickerwheel to be able to change each day.
     
  2. newtoiphonesdk thread starter macrumors 6502a

    Joined:
    Jul 30, 2010
    #3
    Here is what I have so far:

    Code:
    -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {
        return 1;
    }
    
    -(NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {
        NSCalendar *currentCalendar = [NSCalendar currentCalendar];
        NSDate *today = [NSDate date];
        NSInteger dc = [currentCalendar  ordinalityOfUnit:NSDayCalendarUnit
                                                   inUnit:NSYearCalendarUnit
                                                  forDate:today];
       
        return dc;
    }
    -(NSInteger)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
        return [options objectAtIndex:row];
    }
    -(void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
        NSString *string = [NSString stringWithFormat:@"%@", [options objectAtIndex:row]];
      
       }
    
    - (void)viewWillAppear:(BOOL)animated
    {
        self.title = @"Settings";
        explain.font = [UIFont fontWithName:@"Papyrus" size:24];
        options = [[NSMutableArray alloc]init];
       //here is where I'm not sure how to add one item for each day in the year it is.  For example, today is the 4th day of the year, so I would like the items in the array to be Day:1, Day:2, Day:3, Day:4.
    
        [super viewWillAppear:YES];
       
    }
    
     
  3. CodeBreaker macrumors 6502

    Joined:
    Nov 5, 2010
    Location:
    Sea of Tranquility
    #4
    So why do you need an array for this?

    In your pickerView:didSelectRow:inComponent and the titleForRow: methods just create a string using the row index and the total days.
    *
     

Share This Page