iT邦幫忙

2021 iThome 鐵人賽

DAY 11
0
自我挑戰組

來寫看看app好了! Swift探索之旅系列 第 11

Day#11 測試畫面

前言

承接昨天的內容,今天來開工啦

學習資源

這篇的資源參考與上一週同樣教學團隊的real-time開發影片
Swift 5: Firebase Chat App (Real-Time - 2020)

後來發現Real-time影片會比較零碎,可能的話我盡量把相同區塊的程式放在一起。

更多設定

點選專案,General這邊可以設定一些資訊
由於這個app只會有一個方向,故可以把landscape的設定都取消打勾。

接著再到Info.plist將多餘的item刪除

Cocoa Touch Files

昨天在新增view controller的時候,只有簡單帶到新增檔案,沒有提到要選擇cocoa touch class。簡單來說,Cocoa touch已經將我們所需的架構提供好,我們在既有的framework下進行開發會更快速方便。

Cocoa Touch is a UI Framework used for building software programs to run on iOS. You can think of it as a swift file that comes "ready made" with a few things for you to use. For example, the UITableViewController Cocoa Touch object comes pre-filled with methods necessary to make the table view work. UICollectionViewController is another example.

A swift file is just that - an empty swift file. There is nothing pre-populated inside of it. Empty swift files are typically used for custom classes, structs, enums, etc. Once you start building more applications the difference will become apparent.

測試 畫面是否能正常顯示

LoginViewController

如果當前直接執行程式,會進入conversationViewController的畫面中,因為我們把預設viewController改名字成conversationViewController,所以也需在storyboard修改所連結到的class名稱
總之,改好後執行沒有問題,不過顯示起來就是空白畫面,因此我們加上個背景色然後執行。

import UIKit

class LoginViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }

}

ConversationViewController

import UIKit

class ConversationViewController: UIViewController {

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

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

        let isLoggedIn = UserDefaults.standard.bool(forKey: "logged_in")

        if !isLoggedIn {
            let vc = LoginViewController()
            let nav = UINavigationController(rootViewController: vc)
            nav.modalPresentationStyle = .fullScreen // if not-> pop up as a card
            present(nav, animated: true)
        }
    }


}

到這邊就可以執行程式,成功的畫面可以看到紅色的背景!

結語

最近突然很忙,因此文章比較短QQ。
明天開始實作註冊的畫面,好期待R!

參考資料

what is the difference between a cocoa toach file and a swift file ?

若上述內容有誤或可以改進的部分,歡迎留言以及提出任何指教~
謝謝ヽ(✿゚▽゚)ノ


上一篇
Day#10 初始專案...again (+版本控制)
下一篇
Day#12 登入畫面(1)
系列文
來寫看看app好了! Swift探索之旅30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言