步伐运行后,没有显示赤色背景,并且出现了报错,阐明没有加载到 ViewController ,检查一下。
Thread 1: “Could not find a storyboard named ‘Main’ in bundle NSBundle </Users/dengming/Library/Developer/CoreSimulator/Devices/E911900E-95D7-40F2-BDA0-F7EDCF15F82E/data/Containers/Bundle/Application/D17467AA-3EA9-4577-8B0B-9C16FC6941D9/cmMusic.app> (loaded)”
将target中info 中的 Main storyboard file base name 属性值,设置为空。
再次运行,已经可以成功加载到 ViewController ,并移除了故事板。
实现效果
附:AppDelegate 和 ViewController 代码
//
// ViewController.swift
// cmMusic
//
// Created by deng ming on 2025/2/4.
//
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
view.backgroundColor = .red
// self.view.backgroundColor = .red
}
}
//
// ViewController.swift
// cmMusic
//
// Created by deng ming on 2025/2/4.
//
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.