How to hide first section header in UITableView (grouped style)

前端 未结 15 913
[愿得一人]
[愿得一人] 2020-12-07 11:15

As the design of table views using the grouped style changed considerably with iOS 7, I would like to hide (or remove) the first section header. So far I haven\'t managed to

15条回答
  •  不思量自难忘°
    2020-12-07 11:40

    This is how to hide the first section header in UITableView (grouped style).

    Swift 3.0 & Xcode 8.0 Solution

    1. The TableView's delegate should implement the heightForHeaderInSection method

    2. Within the heightForHeaderInSection method, return the least positive number. (not zero!)

      func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
      
          let headerHeight: CGFloat
      
          switch section {
          case 0:
              // hide the header
              headerHeight = CGFloat.leastNonzeroMagnitude
          default:
              headerHeight = 21
          }
      
          return headerHeight
      }
      

提交回复
热议问题