diff --git a/0170-uikit-navigation-pt2/SwiftUINavigation/SwiftUINavigation/ItemRowCellView.swift b/0170-uikit-navigation-pt2/SwiftUINavigation/SwiftUINavigation/ItemRowCellView.swift index cd3a25fc..72506d5a 100644 --- a/0170-uikit-navigation-pt2/SwiftUINavigation/SwiftUINavigation/ItemRowCellView.swift +++ b/0170-uikit-navigation-pt2/SwiftUINavigation/SwiftUINavigation/ItemRowCellView.swift @@ -29,9 +29,13 @@ class ItemRowCellView: UICollectionViewListCell { case .none: guard let vc = presentedViewController else { return } - vc.dismiss(animated: true) - context.navigationController?.popToViewController(vc, animated: true) - context.navigationController?.popViewController(animated: true) + + if context.navigationController?.viewControllers.contains(vc) == true { + context.navigationController?.popToViewController(vc, animated: true) + context.navigationController?.popViewController(animated: true) + } else { + vc.dismiss(animated: true) + } presentedViewController = nil case .deleteAlert: