如何在 Storyboard 中将 ViewController.swift 连接到 ViewController? [英] How to connect ViewController.swift to ViewController in Storyboard?

查看:16
本文介绍了如何在 Storyboard 中将 ViewController.swift 连接到 ViewController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Storyboard 中创建了一个新的视图控制器,并创建了一个继承 UIViewController 的新 .Swift 文件.但是,我的 viewDidLoad() 没有被调用.

我需要做什么才能将我的故事板中的视图控制器连接到我的 .swift 代码以便 viewDidLoad() 被调用?

我看到是这样的:如何将故事板连接到视图控制器>

然而,在默认项目中,FirstViewController(storyboard) 在那个框中没有 FirstViewController,它是空的,但 viewDidLoad() 仍然被调用.没有意义.

解决方案

  1. 在故事板或场景列表中选择您的 ViewController(我的名为 Circuit).
  2. 点击右侧的Identity Inspector
  3. 选择自定义类>类 >输入 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.

解决方案

  1. Choose your ViewController in the storyboard or scene list (mine is called Circuit).
  2. Click on the Identity Inspector on the right
  3. Select Custom Class > Class > Type name of your swift file.

DONE :)

这篇关于如何在 Storyboard 中将 ViewController.swift 连接到 ViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆