LoginSignup
9
4

More than 5 years have passed since last update.

iOS11 groupedなtableViewのheightForHeaderInSection heightForFooterInSection がおかしい?

Last updated at Posted at 2017-09-23

セクションの高さを変更できない

iOS11対応をしていて、セクションの高さが変わらずハマりました。
解決したのでメモです。

下記のように一番上の高さがなくなるようにしています。

Swift4
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return .leastNonzeroMagnitude
    }

比較

iOS10.3
Simulator Screen Shot - iPhone 6s Plus - 2017-09-23 at 14.35.27.png

iOS11
Simulator Screen Shot - iPhone 8 Plus - 2017-09-23 at 14.35.33.png

解決方法

下記のメソッドを追加してやることで解決しました。
※今回の場合はviewForFooterInSectionは不要です。Footerの高さを変更する場合に必要です。

Swift4
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        return nil
    }

    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        return nil
    }

下記のようにiOS11でも一番上の高さがなくなりました!
Simulator Screen Shot - iPhone 6s Plus - 2017-09-23 at 14.35.27.png

最後に

viewForHeaderInSection、viewForFooterInSectionのデフォルトの動きが変わったんですかね、、、?
書いてないとnilを返さなくなった、、、?
詳しい方、おられましたら教えてください。

9
4
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
4