Changing the screen height of an iOS8 table when rotating a device in Swift

I am trying to use the new auto size for my tableview. Im doing this:

    tableView.rowHeight = UITableViewAutomaticDimension

I have a multi-line uilabel in my UITableViewCell with some restrictions that work great; row height is dynamic when I enter the table view in both landscape and portrait! Fine!

... but when I rotate the device, the rows get the base height (i.e. 44).

I added this line:

override func willAnimateRotationToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) 
{
    self.tableView.reloadData()
}

And the problem disappears. But is it really necessary? Should there be a better way to fix this?


Edit:

I just found out that the same problem occurs when I delete a row as a table as follows:

tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)

Am I missing something? Why does it work out of the box?


Change again:

Now I do like this:

self.tableView.estimatedRowHeight = 44
tableView.rowHeight = UITableViewAutomaticDimension

, API:

self.tableView.reloadData()
self.tableView.beginUpdates()
self.tableView.endUpdates()

, , , , ! / . ( .)

. , .

+4
2

, tableView . See- > Swift searchBar View searchController.active :

Swift searchBar View searchController.active

i.e.:

override func willAnimateRotationToInterfaceOrientation(toInterfaceOrientation:      UIInterfaceOrientation, duration: NSTimeInterval) 
{
   self.tableView.reloadData()
}

viewDidLoad . , .

+4

WWDC , Autolayout, . , systemLayoutSizeFittingSize:(CGSize), , sizeThatFits:(CGSize)

, iOS7, , tableView.rowHeight tableView.estimatedRowHeight , , , iOS .

, , , " " UILabel ( , "" ) lines "0". . . . " " iOS UILabel .

, , :

-willTransitionToSize:withTransitionCoordinator: -willTransitionToTraitCollection:withTransitionCoordinator:

0

All Articles