UITableView content height

前端 未结 4 1103
南方客
南方客 2021-01-13 09:02

I have a UITableView that is set to not enable scrolling, and it exists in a UIScrollView. I\'m doing it this way as the design specs call for something that looks like a t

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-13 09:18

    UITableView is a subclass of UIScrollView, so it has a contentSize property that you should be able to use no problem:

    CGFloat tableViewContentHeight = tableView.contentSize.height;
    scrollView.contentSize = CGSizeMake(scrollView.contentSize.width, tableViewContentHeight);
    

    However, as several other SO questions have pointed out, when you make an update to a table view (like inserting a row), its contentSize doesn't appear to be updated immediately like it is for most other animated resizing in UIKit. In this case, you may need to resort to something like Michael Manner's answer. (Although I think it makes better sense implemented as a category on UITableView)

提交回复
热议问题