From 108d75e9b48d8742f4e552c7839270c5fc3f144c Mon Sep 17 00:00:00 2001 From: Toni Sevener Date: Wed, 22 Mar 2023 11:32:55 -0500 Subject: [PATCH] Try to fix another TOC crash --- .../ArticleTableOfContentsDisplayController.swift | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Wikipedia/Code/ArticleTableOfContentsDisplayController.swift b/Wikipedia/Code/ArticleTableOfContentsDisplayController.swift index 9f09a064dc7..bf50b6b42e6 100644 --- a/Wikipedia/Code/ArticleTableOfContentsDisplayController.swift +++ b/Wikipedia/Code/ArticleTableOfContentsDisplayController.swift @@ -92,8 +92,14 @@ class ArticleTableOfContentsDisplayController: Themeable { self.viewController.isVisible = true self.selectAndScroll(to: sectionId, animated: false) - // Attempt to fix TOC presentation crashes. - guard !self.viewController.isBeingPresented && self.delegate !== self.viewController else { + // Attempts to fix TOC presentation crashes. Error message target is in comments. + guard + !self.viewController.isBeingPresented && // Application tried to present modally a view controller %@ that is already being presented by %@. + self.delegate?.presentedViewController == nil && // Attempt to present %@ on %@ (from %@) which is already presenting %@. + self.delegate !== self.viewController && // Application tried to present modal view controller on itself. + self.viewController.parent == nil && // Application tried to present modally a view controller %@ that has a parent view controller %@. + (self.delegate?.isViewLoaded ?? false) // Attempt to present %@ on %@ (from %@) whose view is not in the window hierarchy. + else { return } @@ -180,5 +186,4 @@ class ArticleTableOfContentsDisplayController: Themeable { viewController.selectItem(at: index) viewController.scrollToItem(at: index) } - }