From 2a414f91952d5ba7802b4db5da7c023235c722f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B2=E1=84=8C=E1=85=A5=E1=86=BC=E1=84=8C?= =?UTF-8?q?=E1=85=AE?= Date: Fri, 30 Jun 2023 18:45:35 +0900 Subject: [PATCH] =?UTF-8?q?NewGoalVC=EB=A5=BC=20Modal=EB=A1=9C=20=EB=9D=84?= =?UTF-8?q?=EC=9A=B0=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../View/GoalListViewController.swift | 13 ++++++-- .../NewGoal/View/NewGoalViewController.swift | 30 +++++++++---------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/ThreeDayResolution/ThreeDayResolution/Presentation/GoalList/View/GoalListViewController.swift b/ThreeDayResolution/ThreeDayResolution/Presentation/GoalList/View/GoalListViewController.swift index 87e8ba9..c0b1c43 100644 --- a/ThreeDayResolution/ThreeDayResolution/Presentation/GoalList/View/GoalListViewController.swift +++ b/ThreeDayResolution/ThreeDayResolution/Presentation/GoalList/View/GoalListViewController.swift @@ -73,8 +73,10 @@ final class GoalListViewController: UIViewController { //MARK: - Methods @objc private func goGoalVC() { - let goalVC = NewGoalViewController.instantiate - navigationController?.pushViewController(goalVC, animated: true) + if let goalVC = NewGoalViewController.instantiate as? NewGoalViewController { + goalVC.newGoalViewControllerDelegate = self + present(goalVC, animated: true) + } } @objc private func showInfoVC() { @@ -82,7 +84,7 @@ final class GoalListViewController: UIViewController { present(infoVC, animated: true) } - private func goThreeDayVC(goal: Goal) { + func goThreeDayVC(goal: Goal) { guard let threeDayVC = ThreeDayViewController.instantiate as? ThreeDayViewController else { return } @@ -188,3 +190,8 @@ extension GoalListViewController: UICollectionViewDataSource { return headerCell } } + +//MARK: - NewGaolViewControllerDelegate +extension GoalListViewController: NewGoalViewControllerDelegate { + +} diff --git a/ThreeDayResolution/ThreeDayResolution/Presentation/NewGoal/View/NewGoalViewController.swift b/ThreeDayResolution/ThreeDayResolution/Presentation/NewGoal/View/NewGoalViewController.swift index b67352d..bab406b 100644 --- a/ThreeDayResolution/ThreeDayResolution/Presentation/NewGoal/View/NewGoalViewController.swift +++ b/ThreeDayResolution/ThreeDayResolution/Presentation/NewGoal/View/NewGoalViewController.swift @@ -7,6 +7,10 @@ import UIKit +protocol NewGoalViewControllerDelegate: AnyObject { + func goThreeDayVC(goal: Goal) +} + final class NewGoalViewController: UIViewController { //MARK: - Views @@ -19,6 +23,7 @@ final class NewGoalViewController: UIViewController { //MARK: - Properties private let viewModel: NewGoalViewModel = NewGoalViewModel(saveUseCase: .init()) private let maxGoalLength = 15 + weak var newGoalViewControllerDelegate: NewGoalViewControllerDelegate? //MARK: - Life Cycle override func viewDidLoad() { @@ -35,7 +40,16 @@ final class NewGoalViewController: UIViewController { //MARK: - IBActions @IBAction func clickedStartButton(_ sender: UIButton) { - goThreeDayVC() + guard let goalText = goalTextField.text else { + return + } + + let goal = Goal(goal: goalText, createdAt: Date()) + saveGoal(with: goal) + + dismiss(animated: true) { [weak self] in + self?.newGoalViewControllerDelegate?.goThreeDayVC(goal: goal) + } } //MARK: - Setup @@ -107,20 +121,6 @@ final class NewGoalViewController: UIViewController { } //MARK: - Methods - private func goThreeDayVC() { - guard let goalText = goalTextField.text, - let threeDayVC = ThreeDayViewController.instantiate as? ThreeDayViewController else { - return - } - - let goal = Goal(goal: goalText, createdAt: .init()) - - saveGoal(with: goal) - - threeDayVC.goal = goal - navigationController?.pushViewController(threeDayVC, animated: true) - } - private func saveGoal(with goal: Goal) { viewModel.action(.save(goal)) }