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

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

问题描述

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

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

我看到是这样的:如何将情节提要与视图控制器连接

但是,在默认项目中,FirstViewController(storyboard)在该框中没有FirstViewController,它为空,但仍调用viewDidLoad().这没有道理.

解决方案

  1. 在情节提要或场景列表中选择ViewController(我的称为Circuit).
  2. 单击右侧的Identity Inspector
  3. 选择Custom Class > Class > Type name of your swift file.

完成:)

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天全站免登陆