2014-12-04 2 views
0

특정 셀에 대한 제스처가있는 테이블 뷰가 있습니다. 테이블 뷰가로드 된 후, 네 번째 행으로 스크롤하여 왼쪽으로 스 와이프하면 일부 내용이 표시되어 작동합니다. 하지만 그 후 첫 번째 행으로 돌아가서 네 번째 줄에 동일한 내용을 보여줍니다.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

어떤 특정 콘텐츠가 변경됩니까? –

+0

@LyndseyScott - 네 번째 행을 왼쪽으로 스 와이프하고 첫 번째 행을 왼쪽으로 스 와이프합니다. –

답변

0

tableView은 성능을 위해 셀을 재사용하므로 모든 셀을 채우기 전에 모든 셀을 "청소"해야합니다.

희망이 도움이됩니다.

+0

하는 방법 ..? –

+0

내 코드에서 나는 다음과 같이 만듭니다 : cell.textLabel.text = @ "" "; 다른 것을 설정하기 전에이 "self.Name"을 사용하고 있기 때문에 다른 경우가 있습니다.이 위치를 어디에서 변경합니까? –

+0

@Balaji는 SampleViewCell에서 -prepareForReuse 메서드를 재정의하고이 메서드 내에서 모든 것을 기본 상태로 다시 설정합니다. –