diff --git a/Fitfty/Projects/Coordinator/Sources/Main/UploadCodyCoordinator.swift b/Fitfty/Projects/Coordinator/Sources/Main/UploadCodyCoordinator.swift index bb03ca96..e7586b35 100644 --- a/Fitfty/Projects/Coordinator/Sources/Main/UploadCodyCoordinator.swift +++ b/Fitfty/Projects/Coordinator/Sources/Main/UploadCodyCoordinator.swift @@ -55,7 +55,6 @@ private extension UploadCodyCoordinator { extension UploadCodyCoordinator: UploadCodyCoordinatorInterface { func dismissUploadCody(_ viewController: UIViewController) { finishDelegate?.coordinatorDidFinish(childCoordinator: self) - viewController.dismiss(animated: true) } func showAlbum() { diff --git a/Fitfty/Projects/Coordinator/Sources/TabCoordinator.swift b/Fitfty/Projects/Coordinator/Sources/TabCoordinator.swift index 67f5a2ae..d2b334bd 100644 --- a/Fitfty/Projects/Coordinator/Sources/TabCoordinator.swift +++ b/Fitfty/Projects/Coordinator/Sources/TabCoordinator.swift @@ -103,6 +103,7 @@ final class TabCoordinator: NSObject, Coordinator, TabCoordinatorProtocol { switch page { case .weather: let coordinator = MainCoordinator() + childCoordinators.append(coordinator) coordinator.start() let tabBarItem = UITabBarItem.init( title: nil, @@ -114,19 +115,19 @@ final class TabCoordinator: NSObject, Coordinator, TabCoordinatorProtocol { tabBarController.addChild(coordinator.navigationController) case .createCody: - let coordinator = UploadCodyCoordinator() - coordinator.start() + let dummyController = UINavigationController() let tabBarItem = UITabBarItem.init( title: nil, image: page.pageIconImage, tag: page.pageOrderNumber ) - coordinator.navigationController.tabBarItem = tabBarItem + dummyController.tabBarItem = tabBarItem tabBarItem.imageInsets = UIEdgeInsets(top: 13, left: 0, bottom: -15, right: 0) - tabBarController.addChild(coordinator.navigationController) + tabBarController.addChild(dummyController) case .profile: let coordinator = ProfileCoordinator() + childCoordinators.append(coordinator) coordinator.start() let tabBarItem = UITabBarItem.init( title: nil, @@ -170,6 +171,9 @@ extension TabCoordinator: UITabBarControllerDelegate { } if tabBar == .createCody { let coordinator = UploadCodyCoordinator() + childCoordinators.append(coordinator) + coordinator.finishDelegate = self + coordinator.parentCoordinator = self coordinator.start() coordinator.navigationController.modalPresentationStyle = .fullScreen tabBarController.present(coordinator.navigationController, animated: true) @@ -197,3 +201,17 @@ extension TabCoordinator: UITabBarControllerDelegate { } } + +extension TabCoordinator: CoordinatorFinishDelegate { + + func coordinatorDidFinish(childCoordinator: Coordinator) { + childDidFinish(childCoordinator, parent: self) + switch childCoordinator.type { + case .uploadCody: + tabBarController.dismiss(animated: true) { + childCoordinator.navigationController.viewControllers.removeAll() + } + default: break + } + } +} diff --git a/Fitfty/Projects/MainFeed/Sources/Main/Weather/ViewController/WeatherViewController.swift b/Fitfty/Projects/MainFeed/Sources/Main/Weather/ViewController/WeatherViewController.swift index af6f9164..70fb33ba 100644 --- a/Fitfty/Projects/MainFeed/Sources/Main/Weather/ViewController/WeatherViewController.swift +++ b/Fitfty/Projects/MainFeed/Sources/Main/Weather/ViewController/WeatherViewController.swift @@ -30,6 +30,10 @@ public final class WeatherViewController: UIViewController { fatalError("init(coder:) has not been implemented") } + deinit { + coordinator.finished() + } + private lazy var locationView: LocationView = { let locationView = LocationView("성북구 정릉동") let tappedLoacationView = UITapGestureRecognizer(target: self, action: #selector(didTapLoactionView(_:))) diff --git a/Fitfty/Projects/MainFeed/Sources/UploadCody/ViewControllers/AlbumViewController.swift b/Fitfty/Projects/MainFeed/Sources/UploadCody/ViewControllers/AlbumViewController.swift index e3a1e5f3..85b67b98 100644 --- a/Fitfty/Projects/MainFeed/Sources/UploadCody/ViewControllers/AlbumViewController.swift +++ b/Fitfty/Projects/MainFeed/Sources/UploadCody/ViewControllers/AlbumViewController.swift @@ -167,7 +167,7 @@ final public class AlbumViewController: UIViewController { cell?.setImage(image: image) } } - return cell + return cell ?? UICollectionViewCell() }) } diff --git a/Fitfty/Projects/MainFeed/Sources/UploadCody/ViewControllers/UploadCodyViewController.swift b/Fitfty/Projects/MainFeed/Sources/UploadCody/ViewControllers/UploadCodyViewController.swift index 6c68062f..4257091f 100644 --- a/Fitfty/Projects/MainFeed/Sources/UploadCody/ViewControllers/UploadCodyViewController.swift +++ b/Fitfty/Projects/MainFeed/Sources/UploadCody/ViewControllers/UploadCodyViewController.swift @@ -197,7 +197,10 @@ extension UploadCodyViewController { private func setUpDataSource() { dataSource = UICollectionViewDiffableDataSource( collectionView: collectionView, - cellProvider: { collectionView, indexPath, _ in + cellProvider: { [weak self] collectionView, indexPath, _ in + guard let self = self else { + return UICollectionViewCell() + } let section = Section(index: indexPath.section) switch section { case .content: @@ -457,7 +460,7 @@ extension UploadCodyViewController: UICollectionViewDelegate { // MARK: - AlbumAuthorization extension UploadCodyViewController { @objc private func didTapUploadPhotoButton(_ sender: UIButton) { - self.requestAlbumAuthorization { isAuthorized in + requestAlbumAuthorization { [weak self] isAuthorized in if isAuthorized { PhotoService.shared.getAlbums(completion: { [weak self] _ in DispatchQueue.main.async { @@ -465,7 +468,7 @@ extension UploadCodyViewController { } }) } else { - self.showAlertGoToSetting( + self?.showAlertGoToSetting( title: "현재 앨범 사용에 대한 접근 권한이 없습니다.", message: "설정 > 핏프티 탭에서 접근을 활성화 할 수 있습니다." ) @@ -508,8 +511,8 @@ extension UploadCodyViewController { } [cancelAlert, goToSettingAlert] .forEach(alertController.addAction(_:)) - DispatchQueue.main.async { - self.present(alertController, animated: true) + DispatchQueue.main.async { [weak self] in + self?.present(alertController, animated: true) } } } diff --git a/Fitfty/Projects/Setting/Sources/Home/ViewController/SettingViewController.swift b/Fitfty/Projects/Setting/Sources/Home/ViewController/SettingViewController.swift index df2131c8..de956290 100644 --- a/Fitfty/Projects/Setting/Sources/Home/ViewController/SettingViewController.swift +++ b/Fitfty/Projects/Setting/Sources/Home/ViewController/SettingViewController.swift @@ -31,6 +31,10 @@ public final class SettingViewController: UIViewController { fatalError("init(coder:) has not been implemented") } + deinit { + coordinator?.finished() + } + private lazy var collectionView: UICollectionView = { let collectionView = UICollectionView(frame: .zero, collectionViewLayout: createLayout()) collectionView.register(SettingCell.self)