1

Pre iOS7 I would use this bit of code to caclulate how big a UITableView would be and then set its tableView.contentSizeForViewInPopover: (it is a class method to my catagory of UIPopoverController):

+(CGFloat)createContentHeighForTableViewController:(UITableViewController *)viewController {
    CGFloat tableViewHeight = 0;

    for (int i = 0; i < [viewController.tableView numberOfSections]; i++)
    {
        CGRect sectionRect = [viewController.tableView rectForSection:i];

        tableViewHeight += sectionRect.size.height;
    }

    if (tableViewHeight > POPOVER_SIZE.height){
        return POPOVER_SIZE.height;
    }
    else {
        return tableViewHeight;
    }
}

It wasn't perfect, but would work reasonably well:

enter image description here

When I scroll it down, it pulls the tableView back up and it rests where it is in the picture.

Here is why I said my code worked pretty well:

enter image description here

This is the result of scrolling up and it resting with some of the tableview slightly out of the view.

With the move to iOS7 and the same code, this is the result:

enter image description here

That is the default w/out any scrolling.

Its clear that my content size is too small. How can I better calculate the size of the tableView?

Vlad Papko
  • 13,184
  • 4
  • 41
  • 57
Padin215
  • 7,444
  • 13
  • 65
  • 103
  • 1
    Looks to me as if the height is actually correct. Have you checked the Under Top Bars, Under Bottom Bars, and Adjust Scroll View Insets to make sure they're all off? Something else that might help is to disable scrolling for a tableview that fits entirely in the popover. That will also alleviate the problems you're seeing on iOS 6. – David Berry May 07 '14 at 16:21
  • Since I don't know what the "Under Top/Bottom Bars" are, no I haven't. What are those and how do I check them? – Padin215 May 07 '14 at 17:02
  • Please look here starting this answer: http://stackoverflow.com/questions/18388429/uitableview-is-starting-with-an-offset-in-ios-7/19165164#19165164 – Sergei Nikitin May 07 '14 at 18:17

0 Answers0