2

I have 4 view controllers of which 3 are perfectly working. All of them have an own .swift file and are linked using a storyboard. The last view controller doesn't show up properly though there is nothing that could possibly prevent it from doing so.

Here is an extract of the file that calls the last view controller:

func showBook()
{
    self.presentViewController(BookViewController(), animated: true, completion: nil)
}

Here is the file that is called:

import UIKit

class BookViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        print("BookViewController")
    }

}

The code doesn't throw any error, prints "BookViewController" and if I set the background color of the view programmatically, it works just fine. But it doesn't show the content set in the storyboard.

Here is a screenshot of my storyboard (only the relevant part):

Note: All the other view controllers are not shown programmatically but using a "present modally" - segue. When I try and use a "present modally" - segue with the last view controller, it also works fine

2 Answers2

1

I do not use storyBoards myself, but what about your class in identity inspector?

Make sure to select ViewController instead of your View (automatically selected when you click on the view in the storyboard). The difference between them is a blue rectangle around your app when the view controller is selected.

identity inspector

ha100
  • 1,563
  • 1
  • 21
  • 28
0

You need to set the Storyboard ID of your viewcontroller, and use self.storyboard?.instantiateViewControllerWithIdentifier("theIdentifier") instead of creating the BookViewController with a constructor.

ullstrm
  • 9,812
  • 7
  • 52
  • 83