7

I noticed something very strange with Xcode 9. When I'm on my main storyboard and I change the device selected to see the view controllers in the appropriate format, I've noticed that the width of my tableview on the viewDidLoad is wrong if the selected device on the storyboard is different that the device I deploy on. I have done tests and it seems that layout of the selected device on the storyboard is taken.

Does anyone has already experienced this issue?

This issue is also present on the beta version 9.1 of Xcode

1 Answers1

0

I noticed the same problem when trying to apply a mask to my view's layer in order to round corners within a UITableViewCell. This answer did the trick for me.

In layoutSubviews(), call layoutIfNeeded() on any views where you need the true size at runtime. For my usage, it looks like this:

override func layoutSubviews() {
    super.layoutSubviews()

    print("cardView frame: \(cardView.frame)") // Storyboard size
    cardView.layoutIfNeeded()
    print("cardView frame: \(cardView.frame)") // Runtime device size
    // Perform your layout here. 
}

I hope this helps!

JGHof
  • 95
  • 2
  • 9