1
3

More than 5 years have passed since last update.

UITableViewで不自然なスペースが先頭に入る問題

Posted at

現象

UIViewControllerに対してヘッダ用のViewを追加し、そこにMargin0pxでUITableViewを配置したところ、どうも20pxほど謎のスペースが発生する現象が起こりました。

IMG_0003.PNG

tableHeaderViewに0pxのViewを配置したり、sectionHeaderに0pxを設定してもこの問題が解消されることはありませんでした。

対処方法

こちらで解説されていたように、UIViewControllerAdjust Scroll View Insetsのチェックを外せば解消します。

■ Why is there extra padding at the top of my UITableView with style UITableViewStyleGrouped in iOS7
http://stackoverflow.com/questions/18880341/why-is-there-extra-padding-at-the-top-of-my-uitableview-with-style-uitableviewst

StoryboardからUIViewControllerを選択し、チェックを外します。
スクリーンショット 2016-11-30 11.36.21.png

スクリーンショット 2016-11-30 11.png

問題が解消しました。
IMG_0004.PNG

このフラグは、ステータスバーの領域やNavigation Barの領域に当たるExtend Edgesの分だけ自動的にContent Insetsを設定させるためのフラグなんですが、今回のように全画面ではなく画面の途中から始まる場合などに設定されていると無駄にずれるだけなので外しておいた方がいいです。

1
3
0

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
1
3