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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 03:08:08  来源:igfitidea点击:

How to connect ViewController.swift to ViewController in Storyboard?

iosxcodeuiviewcontroller

提问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

  1. Choose your ViewController in the storyboard or scene list (mine is called Circuit).
  2. Click on the Identity Inspectoron the right
  3. Select Custom Class > Class > Type name of your swift file.
  1. 在情节提要或场景列表中选择您的 ViewController(我的称为Circuit)。
  2. 点击Identity Inspector右侧的
  3. 选择Custom Class > Class > Type name of your swift file

DONE :)

完毕 :)

Here are these two steps on image (ugly i know)

这是图像上的这两个步骤(我知道丑陋)