UITableView contentSize UITableView contentSize ios ios

UITableView contentSize


I've been running into the same problem and ended up with this workaround. I'm setting the contentSize right after [self.tableView endUpdates];

[self.tableView endUpdates];NSLog(@"%f", self.tableView.contentSize.height);self.tableView.contentSize = [self.tableView sizeThatFits:CGSizeMake(CGRectGetWidth(self.tableView.bounds), CGFLOAT_MAX)];NSLog(@"%f", self.tableView.contentSize.height);[self.tableView setContentInset:UIEdgeInsetsMake(50, 0, -50, 0)];


I had the same problem using a custom view controller with two child VC's, one being a tableview + fetched results controller.

I would get to the point after adding content from one vc and going back to my table that I wouldn't be able to scroll to new content at bottom.

So in my tableview + fetched results controller I adjust the content size based off of the number of fetched objects I have, regardless of where they came from.

Worst case scenario is that I didn't add any content when showing the VC, but the cost is minimal.

//In my tableview + fetched results controller class-(void)viewDidAppear:(BOOL)animated{    [super viewDidAppear:animated];    NSUInteger objCount = self.fetchedResultsController.fetchedObjects.count;    //My custom cell has a height of 50.0f, yours may not!    CGFloat tableHeight = objCount * 50.0f;    NSLog(@"%i objects, total height: %f",objCount,tableHeight);    [self.tableView setContentSize:CGSizeMake(self.tableView.contentSize.width, tableHeight)];}


I have dynamic tableView with 'UITableViewAutomaticDimension'. Something happens and after reload and it's content size is equal to its frame size. After i manualy put content size to be as table bounds size, everything works. I hope this helps.

table.beginUpdates()table.contentSize = CGSize(width: table.bounds.width, height: table.bounds.height)table.endUpdates()

And this is after I done table.reloadData()