ios 创建新的视图控制器后如何创建视图控制器文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28587577/
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
How do I create a view controller file after creating a new view controller?
提问by Kian Cross
I am developing a tabbed application.
我正在开发一个选项卡式应用程序。
When I create a new view controller and link it to the tab bar controller, unlike the other two default view controllers, this one has no viewcontroller.swift
file.
当我创建一个新的视图控制器并将其链接到标签栏控制器时,与其他两个默认视图控制器不同,这个没有viewcontroller.swift
文件。
How can I create this file?
我怎样才能创建这个文件?
I am using Xcode 6 and developing the app in Swift.
我正在使用 Xcode 6 并在 Swift 中开发应用程序。
回答by Rob
Correct, when you drag a view controller object onto your storyboard in order to create a new scene, it doesn't automatically make the new class for you, too.
正确,当您将视图控制器对象拖到情节提要上以创建新场景时,它也不会自动为您创建新类。
Having added a new view controller scene to your storyboard, you then have to:
将新的视图控制器场景添加到故事板后,您必须:
Create a
UIViewController
subclass. For example, go to your target's folder in the project navigator panel on the left and then control-click and choose "New File...". Choose a "Cocoa Touch Class":And then select a unique name for the new view controller subclass:
Specify this new subclass as the base class for the scene you just added to the storyboard.
Now hook up any
IBOutlet
andIBAction
references for this new scene with the new view controller subclass.
创建一个
UIViewController
子类。例如,转到左侧项目导航器面板中目标的文件夹,然后control单击并选择“新建文件...”。选择“Cocoa Touch Class”:然后为新的视图控制器子类选择一个唯一的名称:
将此新子类指定为您刚刚添加到故事板的场景的基类。
现在使用新的视图控制器子类连接这个新场景的任何
IBOutlet
和IBAction
引用。
回答by Manan Jain
To add new ViewController
once you have have an existing ViewController
, follow below step:
要ViewController
在拥有现有 后添加新的ViewController
,请按照以下步骤操作:
Click on background of
Main.storyboard
.Search and select
ViewController
from object library at the utility window.Drag and drop it in background to create a new
ViewController
.
单击 的背景
Main.storyboard
。ViewController
在实用程序窗口中从对象库中搜索和选择。将其拖放到后台以创建新的
ViewController
.