如何在 Storyboard 中将 ViewController.swift 连接到 ViewController? [英] How to connect ViewController.swift to ViewController in Storyboard?
问题描述
我在 Storyboard 中创建了一个新的视图控制器,并创建了一个继承 UIViewController
的新 .Swift 文件.但是,我的 viewDidLoad()
没有被调用.
我需要做什么才能将我的故事板中的视图控制器连接到我的 .swift 代码以便 viewDidLoad()
被调用?
我看到是这样的:如何将故事板连接到视图控制器>
然而,在默认项目中,FirstViewController(storyboard) 在那个框中没有 FirstViewController,它是空的,但 viewDidLoad()
仍然被调用.没有意义.
- 在故事板或场景列表中选择您的 ViewController(我的名为
Circuit
). - 点击右侧的
Identity Inspector
- 选择
自定义类>类 >输入 swift 文件的名称
.
完成:)
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.
- 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
.
DONE :)
这篇关于如何在 Storyboard 中将 ViewController.swift 连接到 ViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!