0

I have a dynamic table view with sections that I'd like to reuse in other scenarios, however only have certain sections shown. Is there a way I can hide an entire section so that my indexPath.section logic doesn't need to be changed when certain sections aren't shown? I know there's

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    if indexPath.section == 0 {
        return 0
    } 
    return 60.0
}

to hide rows, I use that logic in a separate static tableView. But that still leaves the section header. Is there a way to do this where its seamless, as in hidden sections leave no blank space?

Tommy K
  • 1,759
  • 3
  • 28
  • 51

1 Answers1

0

Based on the second response to this question, you should be able to do this by returning nil from the titleForHeaderInSection method, and 0 from the numberOfRowsInSection method for whichever section you want hidden.

Community
  • 1
  • 1
Jumhyn
  • 6,687
  • 9
  • 48
  • 76