From 8081123cb2039a835a0a2770fa4dcbdcf81ab002 Mon Sep 17 00:00:00 2001 From: Garrett Moon Date: Wed, 6 Jul 2016 13:35:40 -0700 Subject: [PATCH] Fix visibility assert on iOS 7 It appears that didMoveToViewController: can be called with nil, yet self.parentViewController will *not* be nil. This can result in calling parent view controller's visibility depth. Instead of asserting, these methods should return NSNotFound which also happens to be a really large number, effectively infinite depth. --- AsyncDisplayKit/ASNavigationController.m | 5 ++++- AsyncDisplayKit/ASTabBarController.m | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/AsyncDisplayKit/ASNavigationController.m b/AsyncDisplayKit/ASNavigationController.m index bf97b765f5..e67f15e742 100644 --- a/AsyncDisplayKit/ASNavigationController.m +++ b/AsyncDisplayKit/ASNavigationController.m @@ -40,7 +40,10 @@ ASVisibilityDepthImplementation; - (NSInteger)visibilityDepthOfChildViewController:(UIViewController *)childViewController { NSUInteger viewControllerIndex = [self.viewControllers indexOfObject:childViewController]; - NSAssert(viewControllerIndex != NSNotFound, @"childViewController is not in the navigation stack."); + if (viewControllerIndex == NSNotFound) { + //If childViewController is not actually a child, return NSNotFound which is also a really large number. + return NSNotFound; + } if (viewControllerIndex == self.viewControllers.count - 1) { //view controller is at the top, just return our own visibility depth. diff --git a/AsyncDisplayKit/ASTabBarController.m b/AsyncDisplayKit/ASTabBarController.m index 65b31d8137..5dd994e084 100644 --- a/AsyncDisplayKit/ASTabBarController.m +++ b/AsyncDisplayKit/ASTabBarController.m @@ -39,6 +39,12 @@ ASVisibilityDepthImplementation; - (NSInteger)visibilityDepthOfChildViewController:(UIViewController *)childViewController { + NSUInteger viewControllerIndex = [self.viewControllers indexOfObject:childViewController]; + if (viewControllerIndex == NSNotFound) { + //If childViewController is not actually a child, return NSNotFound which is also a really large number. + return NSNotFound; + } + if (self.selectedViewController == childViewController) { return [self visibilityDepth]; }