在第四行更改内容时,uitableview单元格更改第一行中的内容

我有一个特定单元格的手势桌面视图。 在tableview加载后,我滚动到第四行,并向左滑动显示一些内容,其工作正常。 但之后,当我回到第一行,它也显示在第四行相同的内容。

当我运行这个代码与ios8,其工作正常。以上问题只发生在我运行这个在ios7中。

我的代码如下:

- (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; } 

提前致谢。

tableView重用了单元格的性能,所以我所做的是在填充之前“清理”每个单元格。

希望这可以帮助!