Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrong size from UITableView.SizeThatFits()

I implemented an UIPopoverController which is filled with a grouped UITableView. The number of cells in the table view can change dynamicly as long the popover is invisible. As soon as the popover becomes visible, the number of cells are fixed.

When the popover becomes visible, i resize the popover content to the height of the table view. I use the SizeThatFits() method from the UITableView to get the table size and use this value to set the popover PopoverContentSize height.

This works fine when the app is running. But always the first time the popover is shown after a new start of the app, SizeThatFits() delivers a wrong height (about 60 pixel to high). Has anyone an idea what this problem could be?

like image 688
Jörn Avatar asked Oct 09 '22 13:10

Jörn


2 Answers

I had a somewhat similar issue because I was performing my calculations in ViewDidLoad. I was able to work around the issue by creating a bool flag in the view's code and only performing the calculations in ViewDidAppear if the flag was not set (and, of course setting the flag so that the logic wasn't repeated each time).

like image 145
competent_tech Avatar answered Oct 13 '22 10:10

competent_tech


On iOS 5 and up, sizeThatFits on a UITableView gives the correct result when called within the viewDidLayoutSubviews UIViewController method.

like image 29
kevin Avatar answered Oct 13 '22 11:10

kevin