Вам нужно будет создать NSDate
экземпляры вручную, если вам нужно отобразить все даты с 1 января по 31 декабря.
Следующие методы могут помочь с NSDate
экземплярами, которые необходимы для вашего UITableView
ячейки:
- (NSInteger)daysInYear:(NSInteger)year {
if (year % 400 == 0) return 366;
else if (year % 100 == 0) return 365;
else if (year % 4 == 0) return 366;
else return 365;
}
- (NSDate *)firstDayInYear:(NSInteger)year {
NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
[fmt setDateFormat:@"MM/dd/yyyy"];
NSDate *firstDayInYear = [fmt dateFromString:[NSString stringWithFormat:@"01/01/%d", year]];
[fmt release];
return firstDayInYear;
}
- (NSDate *)dateWithDayInterval:(NSInteger)dayInterval sinceDate:(NSDate *)referenceDate {
static NSInteger SECONDS_PER_DAY = 60 * 60 * 24;
return [NSDate dateWithTimeInterval:dayInterval * SECONDS_PER_DAY sinceDate:referenceDate];
}
В вашем tableView: cellForRowAtIndexPath: метод вы можете затем создать соответствующий экземпляр NSDate
:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSDate *dateForCell = [self dateWithDayInterval:indexPath.row sinceDate:self.firstDayInYear];
// ... rest of your method ...
}