我有一个针对特定细胞的手势的tableview。在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;
}
提前致谢。
答案 0 :(得分:0)
tableView
重复使用单元格进行演奏,所以我所做的就是"清理"填充之前的每个细胞。
希望这有帮助!