From 38626e26b158f299b82f9c5394bcdffb8cd9e831 Mon Sep 17 00:00:00 2001 From: jharvey3 Date: Sun, 12 Dec 2021 15:35:58 -0500 Subject: [PATCH] Added this test to the .none case: if context.navigationController?.viewControllers.contains(vc) == true (#107) This issue is mentioned in the transcript of session 170, but not in the video (I don't think). The change prevents a crash when confirming a delete action on an item in the inventory list. The change is just copied from the transcript. --- .../SwiftUINavigation/ItemRowCellView.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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: