xcode Storyboard 中新视图控制器的类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11372208/
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-09-15 00:48:23  来源:igfitidea点击:

Classes for new View Controller in Storyboard

iphoneobjective-ciosxcode

提问by ecnepsnai

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.

在我的故事板中,我拖动了一个新的视图控制器。我的 Storyboard 现在有两个视图控制器:一个是我创建文件时出现的主视图控制器,另一个是拖拽进来的。

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.

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

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.

如何为每个视图控制器链接/创建这些类?有没有一种自动化的方法来做到这一点,或者我做得不对。

回答by Chris McKnight

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

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

  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)
  1. 按 cmd+n 或转到文件 > 新建文件
  2. 选择 Objective-C 类并点击下一步
  3. 在第二个框中键入 UIViewController 并在第一个框中键入新类的名称(类似于 MyClassViewController)
  4. 进入您的故事板,选择您拖出的视图控制器,查看检查器并转到自定义类选项卡并将自定义类设置为您新创建的视图控制器(例如 MyClassViewController)