我開發了一個應用程序。我在那個應用程序中有一個問題。
我想將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
我添加了子視圖的滾動視圖爲4個按鈕(buttonEdit,buttonShare,buttonAdd和buttonDelete)。最初的滾動視圖處於隱藏位置
我的要求是用戶每次滑動滾動視圖時應顯示的單元格。無論何時用戶在單元格上滑動,我都會顯示滾動視圖。
但我的問題是每當我滾動tableview滾動視圖顯示在其他單元格也。我該如何解決這個問題。
由於提前,
Rambabuň
在ExistingCasesCustomCell類中創建一個Bool變量,其值爲NO。刷卡時將其更改爲是。如果cell.yourVar爲NO,則在cellForRowAtIndexPath()中放置一個檢查,否則隱藏滾動視圖顯示scrollView。 – Yogendra