iOS(Swift) - UINavigationController,Coordinator,Protocol-[MVVM Design pattern](1)
こんにちは.
今日紹介する内容は~~
ストーリーボードを使用せずにrootView Controlを設定!
設定したViewControllerをシミュレータにアップロードしてみます!
プロジェクトの作成後!->Coordinator SWIFTファイルを作成してください
ここでViewControllerを移動しましょう.
まず和弦を見てから説明しましょう.
まずはプロトコルでデータを伝えます!!
protocol CoordinatorProtocol {
var childCoordinator : [CoordinatorProtocol] { get }
func goingStart()
}
私はこのプロトコルでデータを伝えます!!
SWIFTはプロトコル向けのプログラミングなので、とても重要な部分です!!
{Get}プロトコルに従うと{Get}、{GetSet}は1つしか実現できません! {get set}すべて実現! すべての宣言の方法とプログラムを実現します! でもやりたくないのは?ㅠㅠ回答)@ojbcオプションを使う~ 簡単ですよね?ほほほ、精霊も覚えておけばよかった!!
協議は重要で、勉強は必要です.私ももっと
うん...では.
皆さん.
private let window : UIWindow
init(window:UIWindow) {
self.window = window
}
それを知っておくべきだと思いますが、省略します!!
これがSceneDelegateとつながっている部分だということはご存知でしょう?!ほほほ
もちろんです.
func goingStart() {
let navigationController = UINavigationController()
let dongGangAjiCoordinator = DongGangAjiCoordi(navigationController: navigationController)
childCoordinator.append(dongGangAjiCoordinator)
dongGangAjiCoordinator.goingStart()
window.rootViewController = navigationController
window.makeKeyAndVisible()
}
gongStartメソッドは何ですか!1行目から見ましょう!
まずビューを切り替えるためにSegeではなくNavigationを使います!
ナビゲーションコントローラのインスタンスを作成します!ほほほ
あ、でも東江AjiCoordi<いきなり出てきたのか!?この犬の糞は何ですか.ぶるぶる震える
この和弦を見ればいい!ほほほ
まずこの部分はfinalに疑問があるかもしれないので説明しましょう!
まずfinalは値タイプの構造について宣言しません!!
classの接頭辞として使用できます
finalが宣言したクラスは継承を阻止します!だからtimeenumやstructに値してfinalを得ることができなくて、ほほほ
したがって、再定義を必要としないclassに宣言するだけでいいです.
DongGangAjiCoordiから協調協定を引き継いだので~
Propertyと方法を実施するので、実施します!!
ここで、Coordinatorのリモコンをクリックすると、このセクションが起動します!
init(navigationController : UINavigationController ) {
self.navigationController = navigationController
}
func goingStart() {
let dongGangAjiVC = DongGangAjiViewController.instantiate()
let ddongViewModel = DongGangAjiViewModel()
dongGangAjiVC.ddongViewModel = ddongViewModel
navigationController.setViewControllers([dongGangAjiVC], animated: false)
}
こちらはちょっと複雑かも!まず、先ほどCoordinatorからinitに移行したnavigationをproperty navigationとして受け入れます!そのNavigationにViewControllerを渡すと画面にViewControllerが表示されます!ほほほ
そして~私はViewControllerを作成します!!
classを作成したばかりのViewControlに変更します.
シーケンスイメージボードIDを変更してinstantiate()コードを記述することもできます.
そして必ずUse Storyboard IDボタンを押してくださいね
Navigationを使っているViewControllerを知りました!
今日紹介する内容は~~
ストーリーボードを使用せずにrootView Controlを設定!
設定したViewControllerをシミュレータにアップロードしてみます!
プロジェクトの作成後!->Coordinator SWIFTファイルを作成してください
ここでViewControllerを移動しましょう.
まず和弦を見てから説明しましょう.
import UIKit
protocol CoordinatorProtocol {
var childCoordinator : [CoordinatorProtocol] { get }
func goingStart()
}
// 파이널은 마음대루!!
final class Coordinator : CoordinatorProtocol{
private(set) var childCoordinator: [CoordinatorProtocol] = []
private let window : UIWindow
init(window:UIWindow) {
self.window = window
}
func goingStart() {
let navigationController = UINavigationController()
let dongGangAjiCoordinator = DongGangAjiCoordi(navigationController: navigationController)
childCoordinator.append(dongGangAjiCoordinator)
dongGangAjiCoordinator.goingStart()
window.rootViewController = navigationController
window.makeKeyAndVisible()
}
}
}
一つ一つ説明していきましょう!まずはプロトコルでデータを伝えます!!
protocol CoordinatorProtocol {
var childCoordinator : [CoordinatorProtocol] { get }
func goingStart()
}
私はこのプロトコルでデータを伝えます!!
SWIFTはプロトコル向けのプログラミングなので、とても重要な部分です!!
⭐️key point⭐️
@objc protocol CoordinatorProtocol {
var childCoordinator : [CoordinatorProtocol] { get }
@objc optional func goingStart()
協議は重要で、勉強は必要です.私ももっと
うん...では.
皆さん.
private let window : UIWindow
init(window:UIWindow) {
self.window = window
}
それを知っておくべきだと思いますが、省略します!!
これがSceneDelegateとつながっている部分だということはご存知でしょう?!ほほほ
もちろんです.
func goingStart() {
let navigationController = UINavigationController()
let dongGangAjiCoordinator = DongGangAjiCoordi(navigationController: navigationController)
childCoordinator.append(dongGangAjiCoordinator)
dongGangAjiCoordinator.goingStart()
window.rootViewController = navigationController
window.makeKeyAndVisible()
}
gongStartメソッドは何ですか!1行目から見ましょう!
まずビューを切り替えるためにSegeではなくNavigationを使います!
ナビゲーションコントローラのインスタンスを作成します!ほほほ
あ、でも東江AjiCoordi<いきなり出てきたのか!?この犬の糞は何ですか.ぶるぶる震える
この和弦を見ればいい!ほほほ
final class DongGangAjiCoordi : CoordinatorProtocol {
private(set) var childCoordinator: [CoordinatorProtocol] = []
private let navigationController : UINavigationController
init(navigationController : UINavigationController ) {
self.navigationController = navigationController
}
func goingStart() {
let dongGangAjiVC = DongGangAjiViewController.instantiate()
let ddongViewModel = DongGangAjiViewModel()
dongGangAjiVC.ddongViewModel = ddongViewModel
navigationController.setViewControllers([dongGangAjiVC], animated: false)
}
}
見てると~もう出来てるよハハまずこの部分はfinalに疑問があるかもしれないので説明しましょう!
まずfinalは値タイプの構造について宣言しません!!
classの接頭辞として使用できます
finalが宣言したクラスは継承を阻止します!だからtimeenumやstructに値してfinalを得ることができなくて、ほほほ
したがって、再定義を必要としないclassに宣言するだけでいいです.
DongGangAjiCoordiから協調協定を引き継いだので~
Propertyと方法を実施するので、実施します!!
ここで、Coordinatorのリモコンをクリックすると、このセクションが起動します!
init(navigationController : UINavigationController ) {
self.navigationController = navigationController
}
func goingStart() {
let dongGangAjiVC = DongGangAjiViewController.instantiate()
let ddongViewModel = DongGangAjiViewModel()
dongGangAjiVC.ddongViewModel = ddongViewModel
navigationController.setViewControllers([dongGangAjiVC], animated: false)
}
こちらはちょっと複雑かも!まず、先ほどCoordinatorからinitに移行したnavigationをproperty navigationとして受け入れます!そのNavigationにViewControllerを渡すと画面にViewControllerが表示されます!ほほほ
そして~私はViewControllerを作成します!!
class DongGangAjiViewController: UIViewController {
//MARK: - Properties
//MARK: - storyboard.instantiateViewController
static func instantiate() -> DongGangAjiViewController {
let storyboard = UIStoryboard(name: "Main", bundle: .main)
let controller = storyboard.instantiateViewController(withIdentifier: "DongGangAjiViewController") as! DongGangAjiViewController
return controller
}
//MARK: -라이프사이클
override func viewDidLoad() {
super.viewDidLoad()
}
}
今からここで放送します~storyboard@をセットしておきますclassを作成したばかりのViewControlに変更します.
シーケンスイメージボードIDを変更してinstantiate()コードを記述することもできます.
そして必ずUse Storyboard IDボタンを押してくださいね
Navigationを使っているViewControllerを知りました!
Reference
この問題について(iOS(Swift) - UINavigationController,Coordinator,Protocol-[MVVM Design pattern](1)), 我々は、より多くの情報をここで見つけました https://velog.io/@leejinseong9410/iOSSwift-UINavigationControllerCoordinatorProtocol-MVVM-Design-pattern1テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol