Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
184 views
in Technique[技术] by (71.8m points)

ios - Get height of UITableView without scroll bars

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?

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

question from:https://stackoverflow.com/questions/2528073/get-height-of-uitableview-without-scroll-bars

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...