ios 如何在 Storyboard 中将 ViewController.swift 连接到 ViewController?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26311000/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to connect ViewController.swift to ViewController in Storyboard?
提问by user83039
I made a new view controller in Storyboard and made a new .Swift file that inherits UIViewController
. However, my viewDidLoad()
is not being called.
我在 Storyboard 中创建了一个新的视图控制器,并创建了一个新的 .Swift 文件,该文件继承了UIViewController
. 但是,我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. It doesn't make sense.
但是,在默认项目中, FirstViewController(storyboard) 在该框中没有 FirstViewController,它是空的,但viewDidLoad()
仍被调用。这没有意义。
回答by Lachtan
- Choose your ViewController in the storyboard or scene list (mine is called
Circuit
). - Click on the
Identity Inspector
on the right - Select
Custom Class > Class > Type name of your swift file
.
- 在情节提要或场景列表中选择您的 ViewController(我的称为
Circuit
)。 - 点击
Identity Inspector
右侧的 - 选择
Custom Class > Class > Type name of your swift file
。
DONE :)
完毕 :)