Swift纯Code之旅 Day2. 「谁是主画面?」

昨天已经将Storyboard相关档案都删除了,那这时候Xcode会不知道Project的起始面画面是哪个ViewController,因此今天就要来设定主画面是哪个ViewController!

这边我会先将系统预设的ViewController更名为MainViewController,以便尔後阅读。
你也可以依照你喜欢的名称去更改ViewController的名称。

首先先按着键盘的Command键,然後对着你的ViewController按下滑鼠左键,就会跳出以下画面:
https://ithelp.ithome.com.tw/upload/images/20210912/201089999gdmtAqXul.png

之後就可以修改名称罗~

更改完名称後按下Rename就完成更名罗。
https://ithelp.ithome.com.tw/upload/images/20210912/20108999Nxxd7An8Dp.png

更名完後先找到SceneDelegate.swift档案,并找到func scene(),做以下改动:

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        guard let window = (scene as? UIWindowScene) else { return }
        self.window = UIWindow(windowScene: window)
        self.window?.rootViewController = MainViewController()
        self.window?.makeKeyAndVisible()
    }

这边就会告诉Xcode此Project的主画面为MainViewController,这时候就可以开始测试罗。
MainViewController的背景色改为蓝色,接着执行看看主画面是否有变成蓝色的吧!

class MainViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = .systemBlue
    }
}

https://ithelp.ithome.com.tw/upload/images/20210912/20108999znC4S5nRGe.png

确实变成蓝色了~

明天准备开始实作闹钟的第一步罗


<<:  Day 12 复习 golang concurrency 语法篇 I

>>:  B+树索引实战篇-Part3(索引用於排序与分组、回表的代价、进一步创建与使用索引)

Day 14 - Arrow Function Expression & this

this 在 JavaScript 里,this 指向 window,在 function 中, t...

Day26 X Memory Management In JavaScript

如果你是写 C/C++ 的开发者,应该对记忆体管理并不陌生,如果你是後端开发者,应该会常常注意服务...

Apple 音乐下载到电脑 5 个方法轻松做到【必学】

把 Apple Music 歌曲下载下来,可以让你在没有网路的时候也能收听音乐。想要下载 Apple...

Day20 Android - Retrofit(Get)

今天主要要来提提Retrofit,Retrofit主要透过interface连线串接以取得资料,像是...

第10车厢-你今天table了吗?tableRWD+简易分页应用篇

本篇延续<第9车厢-使用content:attr()实现tableRWD应用>的版,透过程序自动产...