I have a non scrolling UITableView inside of a larger UIScrollView. Since the table view is non scrolling, I want its frame size to always match its content size.
I have the following method that I call:
- (void)resizeTableViewFrameHeight
{
// Table view does not scroll, so its frame height should be equal to its contentSize height
CGRect frame = self.tableView.frame;
frame.size = self.tableView.contentSize;
self.tableView.frame = frame;
}
The problem is that I must be calling this method at the wrong time (before the contentSize is set). I was wondering, is there a property that I can set on UITableView that will cause its frame to always match its content size automatically?
There is no property that dynamically adjusts table view’s frame. Also, I do not think that a
UITableViewcan calculate its entirecontentSizeup-front because a table view could be practically infinite in size, depending what is specified from itsdatasourceand other delegate methods such asheightForRowAtIndexPath. These methods can be dynamic, making it virtually impossible to predict the entire size of a table view.I conclude that you are perhaps not using this UI element correctly.
Workaround:
By having the frame of the table view constrained to the visible area of the scroll view you could simply allow it to scroll. Perhaps you need to prevent your scroll view from scrolling while the table view is scrolling and vice versa. You could easily do this in the
UIScrollViewdelegate methods.