1

I have a tableView in which I have a header view that I added using drag and drop. I want to hide it in device portrait mode and show it in landscape mode. I applied the orientation condition in the heighForHeaderInSection method and returned height 0 when in portrait mode and 70 when in landscape but it did not work as expected and added a new header space in my tableView.

How can I access the header I created in the storyboard?

Arsh Bhullar
  • 61
  • 1
  • 5

1 Answers1

0

Even though your View object is acting like TableView header but still you can control it with IBOutlet connection. Add an IBOutlet in your UIViewController like following

@IBOutlet weak var tableHeader: UIView!

and add following orientation method to hide/unhide the view with frame change.

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
      if UIDevice.current.orientation.isLandscape {
        self.tableHeader.frame = CGRect(x: 0, y: 0, width: self.tableHeader.frame.width, height: 0)
      } else {
        self.tableHeader.frame = CGRect(x: 0, y: 0, width: self.tableHeader.frame.width, height: 40)
      }
  }
RJ168
  • 1,006
  • 2
  • 12
  • 22