I'm using the below code to retrieve a series of 7 dates, and add them to an NSMutableArray.
That said, I want to display each date stored inside the array in each cell's UILabel (see below). How can I write that UILabel line so that it pulls the date out of weekdates?
Dashboard.h
@property (weak, nonatomic) IBOutlet UITableView *todaytableView;
@property (strong, nonatomic) NSMutableArray *weekdates;
DashboardViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
_weekdates = [[NSMutableArray alloc] init]; //Add this line
NSDate *today = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSCalendar *calendar = [NSCalendar currentCalendar];
dateFormatter.dateFormat = @"ddMMM";
for (UInt16 i = 0; i < 7; i++) {
NSDate *nextDate = [calendar dateByAddingUnit:NSCalendarUnitDay value:i toDate:today options: 0];
[_weekdates addObject:nextDate];
NSLog(@"Weekdate %d = %@", i+1, [dateFormatter stringFromDate: nextDate]);
}
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 6;
}
-(UITableViewCell *)tableView:(UITableView*)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
if (tableView == self.todaytableView) {
static NSString *WeeklyTableIdentifier = @"TimeTableViewCell";
TimeTableViewCell *cell = (TimeTableViewCell *)[self.todaytableView dequeueReusableCellWithIdentifier:WeeklyTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TimeTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.firstLast.text = [NSString stringWithFormat:@"%@", _weekdates[indexPath.row]];
return cell;
}