You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于Xcode 13.2.1中创建ViewController、添加Outlet变量及解决项目界面选项缺失问题的技术咨询

iOS Development Starter Issues in Xcode 13.2.1: Solutions

Hey there! I totally get how overwhelming Xcode can feel when you're just dipping your toes into iOS development—let's work through each of your problems step by step:

1. Missing Interface Options (SwiftUI/UIKit) & No Storyboard/ViewController in Project

The root of this is understanding Xcode 13's project setup flow:

  • When starting a new project, make sure you pick the iOS > App template first.
  • On the next setup screen, you’ll see an Interface dropdown menu—this is where you choose between SwiftUI and UIKit (Storyboard). If you don’t spot this, double-check you selected the correct template (some niche templates skip this option).
  • If you already created a project without this setup (and ended up with only App.swift instead of the expected files), here’s how to add them manually:
    • Right-click your project in the Project Navigator > New File > Select Storyboard (under iOS > User Interface) > Name it Main and click Create.
    • Go to your project’s target settings > Under General > Deployment Info, set Main Interface to your new Main.storyboard.
    • Add a ViewController: Right-click the project > New File > Select UIViewController Subclass (under iOS > Cocoa Touch) > Name it ViewController, uncheck "Also create XIB file", then click Create.
    • Open Main.storyboard, drag a ViewController from the Object Library (right sidebar) onto the canvas. Select this ViewController, go to the Identity Inspector (right sidebar, 3rd icon), and set Class to your ViewController subclass to link them.

2. Creating a ViewController in Xcode 13.2.1

The process varies a bit based on your project type:

  • UIKit (Storyboard) Project:
    • Either drag a ViewController directly onto the Storyboard canvas (as above), then link it to a custom subclass if you need custom logic.
    • Or create a UIViewController subclass file first, then associate it with a Storyboard ViewController via the Identity Inspector.
  • SwiftUI Project (if you want to use UIKit ViewControllers):
    • Create a UIViewController subclass as above, then wrap it in a UIHostingController to integrate it into your SwiftUI flow. Example code:
      struct ViewControllerWrapper: View {
          var body: some View {
              UIHostingController(rootView: YourSwiftUIView()).view
          }
      }
      
    But if you prefer drag-and-drop UI editing, it’s way simpler to start a new project with the UIKit (Storyboard) interface option.

3. Can't Add Outlet Variables

Outlets only work with Storyboard/XIB files—so first confirm your ViewController is linked to a Storyboard:

  • Open Main.storyboard and select the ViewController you want to add an outlet to.
  • Open the Assistant Editor (top-right icon, looks like two overlapping circles) to show your ViewController’s code side-by-side with the Storyboard.
  • Select a UI element (like a Label) in the Storyboard, hold Ctrl, and drag from the element to your ViewController’s code (inside the class, above viewDidLoad()).
  • A popup will appear—name your outlet (e.g., myLabel) and click Connect. If this fails, double-check that your Storyboard ViewController’s Class is set to your custom ViewController subclass (via the Identity Inspector).

4. Can't Find the Area to Drag Labels

  • UIKit (Storyboard) Project: Open Main.storyboard—the large canvas showing your ViewController’s screen is where you drag elements from the Object Library (search for "Label" in the right sidebar and drag it onto the canvas).
  • SwiftUI Project: There’s no drag-and-drop UI builder here—you add text by writing SwiftUI code, e.g., Text("Hello World") inside your View struct. If you prefer visual editing, switch to a UIKit (Storyboard) project.

内容的提问来源于stack exchange,提问作者Cherryman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 15:09:09