Note that there are some explanatory texts on larger screens.

plurals
  1. POShow the week dates in UITableView
    text
    copied!<p>In my app i want to show the week's dates in UITableView. I am trying the below code but it is repeating the same date in all rows. Actually what i want to show is the calendar dates in UITableView but week vise.Below is code i am trying. Hope i made my point clear, if any doubt please ask.</p> <pre><code>-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell; if(tableView == self.mWeekTable) { static NSString *cellIdentifier = @"Cell"; cell = [self.mLocationTable dequeueReusableCellWithIdentifier:cellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; } NSDate *dateForCell = [self dateWithDayInterval:indexPath.row sinceDate:firstDayInYear]; // NSDate *date = [NSDate date]; //NSDate *dateForCell = [self nextDayFromDate:date]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"dd-EEEE"]; NSString *stringFromDate = [formatter stringFromDate:dateForCell]; cell.textLabel.text = stringFromDate; } } - (NSDate *)firstDayInYear:(NSInteger)year { NSDateFormatter *fmt = [[NSDateFormatter alloc] init]; [fmt setDateFormat:@"MM/dd/yyyy"]; firstDayInYear = [fmt dateFromString:[NSString stringWithFormat:@"01/01/%d", year]]; 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]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload