Storyboard中新视图控制器的类 [英] Classes for new View Controller in Storyboard

查看:108
本文介绍了Storyboard中新视图控制器的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的故事板中,我拖动了一个新的视图控制器。我的故事板现在有两个视图控制器:我创建文件时出现的主要视图控制器,以及一个被拖动的视图控制器。

In my storyboard I drag on a new View Controller. My Storyboard now has two view controllers: the main one that came when I created the file, and the one a dragged on.

当我进入助理编辑器时并选择主视图控制器,我得到了ViewController.h类。但是当我选择另一个控制器时,我得到UIViewController.h这是一个Apple文件。

When I go into the 'assistant editor' and select the main view controller, I get the ViewController.h class. But when I select the other controller I get UIViewController.h which is an Apple file.

如何为每个View Controller链接/创建这些类?是否有自动执行此操作的方法,或者我做得不对。

How do I link/create these classes for each View Controller? Is there an automated way to do this, or am I not doing it right.

推荐答案

您需要创建自己的子类UIViewController并将新创建的视图控制器设置为故事板中的自定义类。

You need to create your own subclass of UIViewController and set the newly created view controller as the custom class in the storyboard.


  1. 按cmd + n或转到文件>新建文件

  2. 选择Objective-C类并点击下一步

  3. 在第二个框中键入UIViewController并在第一个框中键入新类的名称(这将是类似于MyClassViewController)

  4. 进入故事板,选择您拖出的View Controller,查看检查器并转到Custom Class选项卡并将自定义类设置为新创建的视图控制器(例如MyClassViewController)

  1. Press cmd+n or go to File > New File
  2. Select Objective-C class and hit next
  3. Type UIViewController into the second box and type a name for the new class in the first box (which will be something like MyClassViewController)
  4. Go into your storyboard, select the View Controller you dragged out, look at the inspector and go to the Custom Class Tab and set the custom class to your newly created view controller (e.g. MyClassViewController)

这篇关于Storyboard中新视图控制器的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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