UITableView content height

前端 未结 4 999
南方客
南方客 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:15

    A more general solution that works for me:

    CGFloat tableViewHeight(UITableView *tableView) {
        NSInteger lastSection = tableView.numberOfSections - 1;
        while (lastSection >= 0 && [tableView numberOfRowsInSection:lastSection] <= 0)
            lastSection--;
        if (lastSection < 0)
            return 0;
        CGRect lastFooterRect = [tableView rectForFooterInSection:lastSection];
        return lastFooterRect.origin.y + lastFooterRect.size.height;
    }
    

    In addition to Andrei's solution, it accounts for empty sections and section footers.

提交回复
热议问题