I have a custom tableview cell in grouptableview. And I have one hidden. I then have to make it visible. Cell tag is 3.
This is not working my code:
if (self.tableView.tag == 3) { self.tableView.hidden = NO; //Not working. }
Just i need make a one row is visible. I hope you understand.
In SWIFT you need to do two things,
HIDE your cell. (because reusable cell may conflict)
Set Height of cell to ZERO.
Look at here,
HIDE you cell.
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 }
Set Height of cell to 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 }
Using this you can remove reusable cell conflict issues.
You can do the same for cell?.tag also to hide specific cell by tag.
Pass the cell height zero
for that specific cell in the heightForRowAtIndexPath:
, it will automatically get hidden:-
- (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; }
Add the following method to your code , it will do the trick . Hope it will help you .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With