获取没有滚动条的UITableView的高度 [英] Get height of UITableView without scroll bars

查看:149
本文介绍了获取没有滚动条的UITableView的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取UITableView的完整高度(即没有更多可滚动的高度)。有没有办法做到这一点?

I need to get the full height of a UITableView (i.e. the height at which there would be nothing more to scroll). Is there any way to do this?

我尝试过 [tableView sizeThatFits:CGSizeZero] 返回一个0x0的CGSize。

I've tried [tableView sizeThatFits:CGSizeZero], but that only returns a 0x0 CGSize.

推荐答案

尝试 contentSize 继承自UITableView的超类UIScrollView。但是,您可能会发现 contentSize 返回不正确或过期的值,因此您应该首先调用 layoutIfNeeded 重新计算表格的布局。

Try the contentSize method, which is inherited from UITableView’s superclass, UIScrollView. However, you may find that contentSize returns an incorrect or out of date value, so you should probably call layoutIfNeeded first to recalculate the table’s layout.

- (CGFloat)tableViewHeight
{
   [tableView layoutIfNeeded];
   return [tableView contentSize].height;
}

这篇关于获取没有滚动条的UITableView的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆