滚动查看显示在多个表格单元格中
我开发了一个应用。 我在那个应用程序中有一个问题。
我想将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)。 最初,scrollview处于隐藏位置
我的要求是每当用户滑动滚动视图应显示的单元格。 无论何时用户在单元格上滑动,我都会显示滚动视图。
但我的问题是每当我滚动tableview滚动视图显示在其他单元格也。 我该如何解决这个问题。
提前致谢,
Rambabu N
您的问题发生是因为单元格在UITableView中回收。 转到您的ExistingCasesCustomCell类,重写prepareForReuse方法并隐藏滚动视图。
-(void) prepareForReuse {
self.scrollView.hidden = YES;
}
链接地址: http://www.djcxy.com/p/60505.html
上一篇: Scrollview is displayed in multiple tableview cells
下一篇: How to change UIButton title which placed in prototype cell?
