在创建新的视图控制器之后,如何创建视图控制器文件?

我正在开发一个选项卡式应用程序。

当我创建一个新的视图控制器并将其链接到选项卡栏控制器时,与其他两个默认视图控制器不同,这个视图控制器没有 viewcontroller.swift文件。

如何创建此文件?

我正在使用 Xcode 6并在 Swift 中开发这个应用程序。

108038 次浏览

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:

  1. 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":

    Cocoa Touch Class

    And then select a unique name for the new view controller subclass:

    UIViewController subclass

  2. Specify this new subclass as the base class for the scene you just added to the storyboard.

    enter image description here

  3. Now hook up any IBOutlet and IBAction references for this new scene with the new view controller subclass.

To add new ViewController once you have have an existing ViewController, follow below step:

  1. Click on background of Main.storyboard.

  2. Search and select ViewController from object library at the utility window.

  3. Drag and drop it in background to create a new ViewController.