我开发了一个应用程序。我在该申请中有一个问题 我想将scrollview添加到tableview单元格。我使用下面的代码创建了tableview单元格。
- (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; }
此处ExistingCasesCustomCell
是我的自定义单元格类。
在ExistingCasesCustomCell
的init方法中,我添加了带有子视图的scrollview作为4个按钮(buttonEdit,buttonShare,buttonAdd和buttonDelete)。最初滚动视图处于隐藏位置
我的要求是每当用户在单元格上滑动时,滚动视图应该显示。每当用户在单元格上滑动时我都会显示滚动视图。
但我的问题是每当我滚动tableview时滚动视图也会显示在其他单元格中。我该如何解决这个问题。
提前谢谢,
Rambabu N
答案 0 :(得分:0)
您的问题发生是因为单元格在UITableView中被回收。转到ExistingCasesCustomCell
班级,覆盖prepareForReuse
方法并隐藏滚动视图。
-(void) prepareForReuse {
self.scrollView.hidden = YES;
}