0

每次在不同日期打开应用程序时,我的应用程序都会添加一个报价。因此,您今天打开它会显示第 1 天报价,然后如果您明天或一周后打开,它会添加第 2 天报价。由于各种原因,我无法使用 iCloud 来确保用户的设备在同一天保持同步。所以,我想添加一个设置,用户可以选择他们在哪一天。我在想的是在那天之前的所有日子里填充 UIPickerWheel。为什么?好吧,报价来自我正在构建的 XML,所以现在可能没有 12 月可用的日子,所以我不希望用户选择第 365 天而没有任何事情发生。因此,在 5 日,我希望 UIPickerWheel 显示第 1 天、第 2 天...、第 5 天。我可以使用以下方法获取一年中的当前日期:

NSCalendar *currentCalendar = [NSCalendar currentCalendar];
NSDate *today = [NSDate date];
NSInteger dc = [currentCalendar  ordinalityOfUnit:NSDayCalendarUnit
                                                  inUnit:NSYearCalendarUnit
                                                 forDate:today];

我想知道的是如何让 UIPickerWheel 显示所有数字,以及 Day 一词。所以每一行都表示第 1 天,直到当前日期。有什么想法吗?

更新:这是我到目前为止所拥有的。在 viewWillAppear 中,我评论了我希望每一行看起来像什么。

这是我到目前为止所拥有的:

-(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];

}
4

0 回答 0