2014-12-04 32 views
0

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

当我用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; 
} 

感谢。

+0

哪些特定内容发生变化? – 2014-12-04 18:33:08

+0

@LyndseyScott - 在第四行向左滑动也会在第一行向左滑动。 – 2014-12-05 04:15:06

回答

0

tableView重复使用细胞的性能,所以我所做的是在填充它们之前“清理”每个细胞。

希望这会有所帮助!

+0

该怎么做..? – 2014-12-04 17:57:32

+0

在我的代码上,我只是做了这样的事情: cell.textLabel.text = @“”; 设置其他的事情之前,但对你的情况是不同的,因为你使用这个“self.Name”,你在哪里改变这个? – 2014-12-04 18:24:50

+0

@Balaji覆盖SampleViewCell中的-prepareForReuse方法,并在此方法中将所有内容重置为默认状态。 – 2014-12-04 19:18:52