uitableview cell changes the content in first row when changing content in fourth row

328 Views Asked by At

I have a tableview with gestures for particular cell. After the tableview loads, i scrolled to the fourth row and swiped left it will show some content, its working fine. But after that when i go back to first row, its also showing the same content in the fourth row.

When I run this code with ios8, its working fine.Above problem is occurred only when I run this in ios7.

My code as follows:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
SampleViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];

if(cell == nil)
{
    cell = [[SampleViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
}

NSMutableDictionary *cellData = [self.databaseCall transactionFromDatabase:indexPath.row Id:self.Id andStageId:self.stageId];

[self setSelectedSegmentColor:cell.repeat];
cell.Description.text = self.Name;
cell.actionDescription.text = self.Name;
cell.tipsDescription.text = [cellData objectForKey:@"tipsDescription"];
UIImage *cellImage = [UIImage imageNamed:[cellData objectForKey:@"categoryImage"]];
NSLog(@"%@", [cellData objectForKey:@"cardType"]);
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[cellData objectForKey:@"actionLink"]];

if([[cellData objectForKey:@"cardType"] isEqualToString:@"2"])
{
    UISwipeGestureRecognizer *swipeLeftGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeftMethod:)];
    swipeLeftGesture.direction = UISwipeGestureRecognizerDirectionLeft;
    [cell.cardDetails addGestureRecognizer:swipeLeftGesture];
    [cell.tryThisButton addTarget:self action:@selector(tryThisButtonPressed:) forControlEvents:UIControlEventTouchDown];

    UISwipeGestureRecognizer *swipeRightGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRightMethod:)];
    swipeRightGesture.direction = UISwipeGestureRecognizerDirectionRight;
    [cell.actionCardReminder addGestureRecognizer:swipeRightGesture];
    [cell.previousButton addTarget:self action:@selector(previousButtonPressed:) forControlEvents:UIControlEventTouchDown];

}
else
{

    for(UIGestureRecognizer *recognizer in cell.cardDetails.gestureRecognizers)
    {
        [cell.cardDetails removeGestureRecognizer:recognizer];
    }

    for(UIGestureRecognizer *recognizer in cell.actionCardReminder.gestureRecognizers)
    {
        [cell.actionCardReminder removeGestureRecognizer:recognizer];
    }

    cell.cardDetails.layer.shadowColor = [UIColor blackColor].CGColor;
    cell.cardDetails.layer.shadowOffset = CGSizeMake(0, 2);
    cell.cardDetails.layer.shadowOpacity = 0.5;
}

cell.weburl.attributedText = str;
cell.Name.text = self.Name;
cell.Image.image = cellImage;
NSLog(@"%d", indexPath.row);

// Configure the cell...
return cell;
}

Thanks in advance.

1

There are 1 best solutions below

2
On

The tableView reuses the cells for performance, so what i do is to "clean" every cell before filling them.

Hope this helps!