I wanted to create a layout for my UITableView such that it's divided into 2 sections:
the first section has 3 rows of standard height (44px),
and the second section has one row, which contains a UITextView which completely fills up this cell. The tricky part is that I want to size this textView's cell row to the height of the visible tableview area, such that the text view takes up the remaining view on screen. How do I find out, within
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
what the remaining height looks like? I had previously made hard-coded assumptions based on the two iPhone screen sizes available (480 and 568) but with the new iPhone6 and iPhone 6+ screen, I don't want to use any assumed values for calculating this.
You already have the height of the table view at tableView.bounds.size.height, you just need the height of the first section subtracted from it. so
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0)
{
return 44;
}
return tableView.bounds.size.height - 44 * 3;
}
With the headers, depending on how they behave, you can use rectForHeaderInSection: or rectForSection: to get the heights
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With