UITableView définit la ligne tableview cachée

J'ai une cellule vue de table personnalisée dans grouptableview. Et j'en ai un caché. Je dois alors le rendre visible. L'label de cellule est 3.

Cela ne fonctionne pas mon code:

if (self.tableView.tag == 3) { self.tableView.hidden = NO; //Not working. } 

Juste j'ai besoin de faire une ligne est visible. J'espère que tu comprends.

Passez la hauteur de cellule zero pour cette cellule spécifique dans heightForRowAtIndexPath: elle sera automatiquement masquée: –

 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { float heightForRow = 40; YourCustomCell *cell =(YourCustomCell *)[tableView cellForRowAtIndexPath:indexPath]; if(cell.tag==3) return 0; else return heightForRow; } 

Ajoutez la méthode suivante à votre code, cela fera l'affaire. J'espère que cela vous aidera.

Dans SWIFT, vous devez faire deux choses,

  1. CACHE ta cellule. (parce que la cellule réutilisable peut entrer en conflit)

  2. Réglez Hauteur de la cellule sur ZERO .

Regarde ici,

  1. CACHE ta cellule.

     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let myCell:UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cellID",for: indexPath) as! UITableViewCell if(indexPath.row < 2){ myCell.isHidden = true }else{ myCell.isHidden = false } return myCell } 
  2. Réglez Hauteur de la cellule sur ZERO .

     func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { var rowHeight:CGFloat = 0.0 if(indexPath.row < 2){ rowHeight = 0.0 }else{ rowHeight = 55.0 //or whatever you like } return rowHeight } 

En utilisant cela, vous pouvez supprimer les problèmes de conflit de cellules réutilisables.

Vous pouvez faire la même chose pour la cellule? .tag aussi pour cacher une cellule spécifique par label.

s'il vous plaît se référer à ce code: –

  - (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section { if(section == theSectionWithoutARow) { if(shouldRemoveTheRow) return [theArrayWithTheSectionContents count] - 1; else return [theArrayWithTheSectionContents count]; } // other sections, whatever } - (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath: (NSIndexPath *)indexPath { // blah blah standard table cell creation id theCellObject; if(indexPath.section == theSectionWithoutARow) { NSInteger theActualRowToDisplay = indexPath.row; if(shouldRemoveTheRow && indexPath.row >= theRowIndexToRemove) { theActualRowToDisplay = indexPath.row + 1; } theCellObject = [theArrayWithTheSectionContents objectAtIndex:theActualRowToDisplay]; } // now set up the cell with theCellObject return cell; } 

J'espère que cela vous aidera