[英]How to connect ViewController.swift to ViewController in Storyboard?
I made a new view controller in Storyboard and made a new .Swift file that inherits UIViewController
.我在 Storyboard 中创建了一个新的视图控制器,并创建了一个继承
UIViewController
的新 .Swift 文件。 However, my viewDidLoad()
is not being called.但是,我的
viewDidLoad()
没有被调用。
What do I need to do to connect my view controller in my story board to my .swift code so viewDidLoad()
is called?我需要做什么才能将我的故事板中的视图控制器连接到我的 .swift 代码以便调用
viewDidLoad()
?
I see there's this: How to connect storyboard to viewcontroller我看到有这个: 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.但是,在默认项目中, FirstViewController(storyboard) 在那个框中没有 FirstViewController,它是空的,但
viewDidLoad()
仍然被调用。 It doesn't make sense.这没有意义。
Circuit
).Circuit
)。Identity Inspector
on the rightIdentity Inspector
Custom Class > Class > Type name of your swift file
.Custom Class > Class > Type name of your swift file
。 DONE :)完毕 :)
Yo have your ViewControler
created with some Objects in it ( UILabel
, UIButton
, UIImage
...)哟,你的
ViewControler
创建了一些对象( UILabel
, UIButton
, UIImage
...)
1 - You need to link your ViewControler in your story board to your ViewController.swift
, to do this follow the pictures 1 - 您需要将您的故事板中的
ViewController.swift
链接到您的ViewController.swift
,按照图片执行此操作
2 - In the class filed put the name of the ViewController class. 2 - 在类字段中输入 ViewController 类的名称。 With that you just linked your storyBoard view controller to your
viewController.swift
class有了它,您只需将您的 storyBoard 视图控制器链接到您的
viewController.swift
类
Class =
ViewController.swift
类 =
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: 3 - 现在你需要创建你想要分配的变量(UILabel, UIButton ... 你在你的故事板中):在这个例子中:
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 4 - 要将故事板中的 UILabel 链接到您的 UILabel 变量或将故事板中的 UIButton 链接到您的 UIButton 变量,请按照以下图像进行操作
First select the view controller in the storyboard首先在storyboard中选择view controller
Second select the parragraf icon in the right up corner ands clicked 'Assistant', it will open a screen of your ViewControler.swift
其次选择右上角的 parragraf 图标并单击“助手”,它将打开您的
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请记住对所有变量执行此操作,您需要为故事板中的每个对象创建一个变量
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.