Scrollview is displayed in multiple tableview cells

I developed one application. I have one issue in that application.
I want to add the scrollview to the tableview cell. I created the tableview cell by using below code.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"Cell";
    ExistingCasesCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[ExistingCasesCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
//Adding SwipeGestures to a cell
        UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
        [swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
        [cell addGestureRecognizer:swipeRight];
        swipeRight=nil;

        UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
        [swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
        [cell addGestureRecognizer:swipeLeft];
        swipeLeft=nil;
    }
    cell.buttonEdit.tag=tagForButtonCustomCell*indexPath.row+0;
    [cell.buttonEdit addTarget:self action:@selector(btnOptionsClicked:) forControlEvents:UIControlEventTouchUpInside];
    cell.buttonShare.tag=tagForButtonCustomCell*indexPath.row+1;
    [cell.buttonShare addTarget:self action:@selector(btnOptionsClicked:) forControlEvents:UIControlEventTouchUpInside];
    cell.buttonAdd.tag=tagForButtonCustomCell*indexPath.row+2;
    [cell.buttonAdd addTarget:self action:@selector(btnOptionsClicked:) forControlEvents:UIControlEventTouchUpInside];
    cell.buttonDelete.tag=tagForButtonCustomCell*indexPath.row+3;
    [cell.buttonDelete addTarget:self action:@selector(btnOptionsClicked:) forControlEvents:UIControlEventTouchUpInside];
    Item *itemObject = [arrSavedDocuments objectAtIndex:indexPath.row];
    UILabel *labelDocumentName=(UILabel *)[cell.contentView viewWithTag:tagForLabelDocument];
    labelDocumentName.text=itemObject.itemTypeName;
    UILabel *labelNumOfPages=(UILabel *)[cell.contentView viewWithTag:tagForLabelNumberOfPages];
    labelNumOfPages.text=[NSString stringWithFormat:@"%d", [[itemObject.itemToPage allObjects]count]];
    UILabel *labelDate=(UILabel *)[cell.contentView viewWithTag:tagForLabelDate];
    labelDate.text=[self parseDateString:itemObject.itemCreatedTimeStamp];
    return cell;
}

Here ExistingCasesCustomCell is my custom cell class.
In init method of ExistingCasesCustomCell i added the scrollview with subviews as 4 buttons (buttonEdit, buttonShare, buttonAdd and buttonDelete). Initially scrollview is in hidden position
My Requirement is whenever user swipe on cell the scrollview should display. Whenever user swipe on cell i showed the scrollview.
But my problem is whenever i scroll the tableview the scroll view is displayed in other cells also. How can i resolve this issue.

Thanks in advance,
Rambabu N


Your problem happens because the cells are recycled in a UITableView. Go to your ExistingCasesCustomCell class, override the prepareForReuse method and hide the scroll view.

-(void) prepareForReuse {
    self.scrollView.hidden = YES;
}
链接地址: http://www.djcxy.com/p/60506.html

上一篇: 如何检测tableView单元格被触摸或快速点击

下一篇: 滚动查看显示在多个表格单元格中