Reputation: 3167
I made a new view controller in Storyboard and made a new .Swift file that inherits UIViewController
. However, my viewDidLoad()
is not being called.
What do I need to do to connect my view controller in my story board to my .swift code so viewDidLoad()
is called?
I see there's this: How to connect storyboard to viewcontroller
However, in a default project, FirstViewController(storyboard) doesn't have FirstViewController in that box, it is empty, yet viewDidLoad()
is still called. It doesn't make sense.
Upvotes: 60
Views: 90533
Reputation: 1402
You have your ViewControler
created with some Objects in it (UILabel
, UIButton
, UIImage
...)
1 - You need to link your ViewControler in your story board to your ViewController.swift
, to do this follow the pictures
2 - In the class filed put the name of the ViewController class. With that you just linked your storyBoard view controller to your viewController.swift
class
Class =
ViewController.swift
3 - Now you need to cretae the variables you want to asign(UILabel, UIButton ... that you have in your storyboard): in this example:
class MovieDetailViewController: UIViewController, DetailView {
var presenter: MovieDetailPresenter!
var movie: Movie?
@IBOutlet weak var lblMovieYear: UILabel!
@IBOutlet weak var lblMovieTitle: UILabel!
@IBOutlet weak var movieImage: UIImageView!
@IBOutlet weak var lblMovieRating: UILabel!
@IBOutlet weak var lblMovieOverview: UILabel!
}
4 - To link the UILabel in the story board to your UILabel variable or your UIButton in your story board to your UIButton var, follow the next images
First select the view controller in the storyboard
Second select the parragraf icon in the right up corner ands clicked 'Assistant', it will open a screen of your ViewControler.swift
Now you just need to drag the variable to the corresponding object and you will be done.
Remember to do this with all variables, you will need to create a variable for each object you have in the storyboard
Upvotes: 8
Reputation: 34255
Connect storyboard and view controller
You should set ViewController in
Class` field
Upvotes: 2
Reputation: 5172
Circuit
).Identity Inspector
on the rightCustom Class > Class > Type name of your swift file
.DONE :)
Upvotes: 120