LoginSignup
13
11

More than 5 years have passed since last update.

UITableViewのtableHeaderView/tableFooterViewで高さが合わない問題

Last updated at Posted at 2014-07-22

tableHeaderView/tableFooterViewの高さがUITableViewのスクロール領域に反映されないとき

UITableViewを使用しているとtableHeaderView/tableFooterViewに
UIViewが設定できるけど、代入の順番を間違えるとUITableViewのContentSizeに反映されない。

たとえばフッタに広告を設定するとき

    // 広告設定
    _bannerView= [[[GADBannerView alloc] init] autorelease];
    _bannerView.backgroundColor = [UIColor blackColor];
    _bannerView.frame = CGRectMake(0,
                                   0,
                                    GAD_SIZE_320x50.width, GAD_SIZE_320x50.height);        
    self.tableView.tableFooterView = _bannerView;

Viewのframeを設定してからtableFooterViewに代入すればちゃんとContentSizeにも反映される。

これはダメ

    // 広告設定
    _bannerView= [[[GADBannerView alloc] init] autorelease];
    self.tableView.tableFooterView = _bannerView;

    _bannerView.backgroundColor = [UIColor blackColor];
    _bannerView.frame = CGRectMake(0,
                                   0,
                                    GAD_SIZE_320x50.width, GAD_SIZE_320x50.height);        

tableFooterViewに代入してからframeを設定し直すと、上のレイヤーであるUITableViewのContentSizeまで変更が伝わらないみたい

13
11
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
13
11