1

I have a table view with header and footer in every section. When the device rotates, the headers resizes to fit the table's width, but the footers remains with portrait width.

I tried setting a large width in the xib file, and it works for the header, but no effect on footer.

I also tried doing a reload data in

viewWillTransitionToSize

and it works, but I feel like is not the best way to do it, it also has a weird animation while rotating.

2 Answers2

0

You might use viewWillLayoutSubviews(). This question should be helpful but this is bassically called whenever the view controller views is about to layout its subviews.

So your code will look like this:

override func viewWillLayoutSubviews() {
   super.viewWillLayoutSubviews()
   if UIInterfaceOrientationIsLandscape(UIApplication.sharedApplication().statusBarOrientation) {
      //here you can do the logic for the cell size if phone is in landscape
   } else {
         //logic if not landscape 
     }
 self.tableView.reloadData()
}
Pushpendra
  • 1,492
  • 1
  • 17
  • 33
  • Any idea why `viewWillLayoutSubviews` is triggered over and over again if I set the `tableView.ContentSize` to some arbitrary value inside the same method? – rraallvv Feb 05 '18 at 02:12
0

I solved it, with estimatedRowHeight. I don't know why but after that, the footer resized properly.