Alex Alex - 2 months ago 9
Swift Question

View controls do not show up using Interface Builder

Even I'm a Swift beginner, it should be simple but I don't know why. I'm not keen to use Storyboard so I decided to go for the Interface Builder. After adding several elements into my view controller, they are not showing up when I run my app. The following is my code:

window = UIWindow.init(frame: UIScreen.main.bounds)
let home = HomeViewController()
window!.rootViewController = home
window!.makeKeyAndVisible()


I've already set
HomeViewController
to the
File's Owner

Answer

The problem would be this line:

let home = HomeViewController()

You should change it to

let home = HomeViewController(nibName: "Whatever the name of your xib file is", bundle: nil)