how can i make each cell unique when i add a label to the dynamic cells because when it is scrolled they overwrite each other`
`
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
if ([cell isKindOfClass:[MessageCellInStream class]])
{
MessageCellInStream *mcell = (MessageCellInStream *) cell;
MOC2CallEvent *event = [self.fetchedResultsController objectAtIndexPath:indexPath];
timeStampLabel = (UILabel*)[mcell viewWithTag:550411];
if(!timeStampLabel)
{
// If the label does not exist, create it
CGRect timeStampLabelRect = CGRectMake(200, 8, 100, 20);
timeStampLabel = [[UILabel alloc] initWithFrame:timeStampLabelRect];
timeStampLabel.textAlignment = NSTextAlignmentCenter;
timeStampLabel.font = [UIFont italicSystemFontOfSize:12];
[timeStampLabel setTextColor:[UIColor whiteColor]];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"H:mm"];
NSString *timeStampString = [dateFormatter stringFromDate:event.timeStamp];
timeStampLabel.text = timeStampString;
[mcell.contentView addSubview: timeStampLabel];
}
}
if ([cell isKindOfClass:[MessageCellOutStream class]])
{
MessageCellOutStream *mcella = (MessageCellOutStream *) cell;
MOC2CallEvent *event = [self.fetchedResultsController objectAtIndexPath:indexPath];
timeStampLabel = (UILabel*)[mcella viewWithTag:550410];
if(!timeStampLabel)
{
// If the label does not exist, create it
CGRect timeStampLabelRect = CGRectMake(0, 8, 100, 20);
timeStampLabel = [[UILabel alloc] initWithFrame:timeStampLabelRect];
timeStampLabel.textAlignment = NSTextAlignmentCenter;
timeStampLabel.font = [UIFont italicSystemFontOfSize:12];
[timeStampLabel setTextColor:[UIColor whiteColor]];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"H:mm"];
NSString *timeStampString = [dateFormatter stringFromDate:event.timeStamp];
timeStampLabel.text = timeStampString;
[mcella.contentView addSubview: timeStampLabel];
}
//timeStampLabel = nil;
}
return cell;
}
So any reuse identifier for each cell may help but some methods didnt work each cell has its own cellIdentifier.
Thanks in advance