UITableView: changing footer view's size programmatically doesn't work

29,905
myTable.tableFooterView = myFooterView;

Re-assign your footer view to the table. The table will recognize it has a new footer and re-do whatever layout needs to occur for the proper size of the footer.

Share:
29,905

Related videos on Youtube

hzxu
Author by

hzxu

Updated on July 09, 2022

Comments

  • hzxu
    hzxu almost 2 years

    My table view's footer is a view that shows some tweets from a user, so I do not know its height until I got the tweets, I created a FooterViewController that has a method refreshTweets, I add it in viewDidLoad:

    FooterViewController *controller = [[FooterViewController alloc] initWithNibName...];
    [[self tableView] setFooterView:[controller view]];
    [controller refreshTweets];
    

    in refreshTweets method, I read tweets and calculate the total height, and reset view(the footer)'s height:

    self.view.frame = newFrame;
    

    but it does not make sense, the footer's height is still the height I set in Interface Builder, is there anything missing or any alternative way of doing this?

    Thanks!

    edit: I can change the view's size to be small enough in interface builder, and it will be enlarged after calculating tweets' height and setting view.frame, but the table view still thinks its footer has previous height, that is, the extra space is outside of the tableview and I can only see it if I drag the table up.

  • weienw
    weienw over 10 years
    One helpful (and more verbose) link might be this one about resizing the tableHeaderView; works perfectly for tableFooterView, too: davidjhinson.wordpress.com/2009/03/24/…
  • Skoua
    Skoua over 5 years
    This doesn't work as of iOS11 but here's a similar answer which does: stackoverflow.com/a/28102175/918602
  • Will
    Will over 5 years
    This question is about the footerView of the tableview, not for a specific section of the tableview, which is different.

Related