goks goks - 2 months ago 5x
iOS Question

UItableView one cell repeats 13 times in each section

I'm developing an iOS app using objective-c. I'm having custom cell in

. the section and rows in section count is unknown every time ,
the problem I'm facing is each row in one section repeats 13 times then same with next section my code for tableview is

static NSString *cellIdentifier = @"Cell";
ProductCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];

if (cell == nil) {
cell = [[ProductCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
NSDate *dateRepresentingThisDay = [self.sorteddays objectAtIndex:indexPath.section];
eventsOnThisDay = [self.sections objectForKey:dateRepresentingThisDay];

double interval =[[eventsOnThisDay objectAtIndex:indexOfDateWithTime] doubleValue];
NSDate *celldate=[[NSDate alloc]initWithTimeIntervalSince1970:interval];
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"dd-MMM-yyyy h:mm a"];
cell.TitleLabel.text=[NSString stringWithFormat:@"%@", [eventsOnThisDay objectAtIndex:indexOfTitle]];
cell.DateTimeLabel.text=[NSString stringWithFormat:@"%@", [dateFormatter stringFromDate:celldate]];
cell.NameLabel.text=[NSString stringWithFormat:@"%@", [eventsOnThisDay objectAtIndex:indexOfName]];
cell.backgroundColor=[UIColor clearColor];

return cell;

self.section is
with date key for particular product array/arrays on that day and i am getting this kind of result



I notice that the data for display for every row is based on dateRepresentingThisDay,but the value of it, is based on section. Check your code:

NSDate *dateRepresentingThisDay = [self.sorteddays objectAtIndex:indexPath.section];

So, in the same section, for all cell's the data is the same!