每次在不同日期打开应用时,我的应用都会添加报价。所以,你今天打开它显示第1天报价,然后如果你明天打开,或者在一周内,它会增加第2天报价。由于各种原因,我无法使用iCloud确保用户的设备在同一天保持同步。所以,我想添加一个设置,用户可以选择他们在哪一天。我想到的是UIPickerWheel填充了当天的所有日子。为什么?好吧,引用来自我正在构建的XML,因此我现在可能没有几天可用,所以我不希望用户选择Day 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];
}