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 ?

若上述内容有误或可以改进的部分,欢迎留言以及提出任何指教~
谢谢ヽ(✿゚▽゚)ノ


<<:  [iT铁人赛Day26]练习题(5)

>>:  ASP.NET MVC 从入门到放弃(Day21)-MVC查询资料介绍

推荐好用的 Nutanix Leap

此文由 Nutanix 首席技术营销工程师 Dwayne Lessner 撰写 Nutanix/X...

Proxy 代理模式

今天要谈到代理模式,其实跟昨天的装饰器模式很类似。代理模式的目的在於,因应某些条件替换物件原本的行为...

Day-17 你在专案中负责什麽项目?遇到什麽困难?怎麽解决?

如果你有专案,有作品,通常一定会问你这类题目,而且你的回答很重要,千万要小心作答! 以我自身的例子...

Sass @import DAY34

今天我们要来学习如何把Sass切分支许多档案 这样会使我们比较容易管理 @import(汇入) 可将...

Day7-在认识 useMemo 前,先认识 React.memo

今天介绍的是避免重新渲染的 HOC(Higher Order Component) React.me...