Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

newtoiphonesdk

macrumors 6502a
Original poster
Jul 30, 2010
567
2
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.
 
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];
   
}
 
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];
   
}

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.
*
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.