2014-12-04 34 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