简体   繁体   English

Swift,UIKit。 寻找协调器模式教程,没有 storyboard

[英]Swift, UIKit. Looking for Coordinator pattern tutorial, NO storyboard

I have searched practically everywhere for some tutorials on Coordinator Pattern with no storyboard.我几乎到处都在搜索关于协调器模式的一些教程,没有 storyboard。

Maybe someone can share his code from Github so I can have look?也许有人可以从 Github 分享他的代码,所以我可以看看?

Is anyone able to recommend something?有人可以推荐一些东西吗? Tutorial, a book to buy, anything.教程,买书,什么都有。 Thanks!谢谢!

I recommend you to read this article by Paul Hudson.我建议您阅读 Paul Hudson 的这篇文章 But it's written by using storyboard .但它是使用storyboard编写的。

If you want to use uikit without storyboard, delete Main.storyboard first.如果要在没有 storyboard 的情况下使用 uikit,请先删除Main.storyboard

Inside Info.plist file, delete the rows with the following keys.Info.plist文件中,使用以下键删除行。

  • Application Scene Manifest/Scene Configuration/Application Session Role/Storyboard Name应用场景清单/场景配置/应用 Session 角色/故事板名称
  • Main storyboard file base name主要 storyboard 文件基名

In SceneDelegate class of SceneDelegate.swift , add this property.SceneDelegate的 SceneDelegate SceneDelegate.swift中,添加此属性。

var coordinator: Coordinator?

Replace the following code in scene(_:willConnectTo:options:) of SceneDelegate.swift替换 SceneDelegate.swift 的scene(_:willConnectTo:options:) SceneDelegate.swift的以下代码

guard let windowScene = (scene as? UIWindowScene) else { return }
let window = UIWindow(windowScene: windowScene)
let navigationController =  UINavigationController()
coordinator = MainCoordinator(navigationController: navigationController)
coordinator?.start()
window.rootViewController = navigationController
self.window = window
window.makeKeyAndVisible()

I hope you may keep on learning coordinator pattern.我希望你可以继续学习协调器模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM