问题
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.
How can I create this file?
I am using Xcode 6 and developing the app in Swift.
回答1:
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.
回答2:
To add new ViewController
once you have have an existing ViewController
, follow below step:
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
.
来源:https://stackoverflow.com/questions/28587577/how-do-i-create-a-view-controller-file-after-creating-a-new-view-controller