UINavigationController cann't work fine
Closed this issue · 1 comments
likid1412 commented
I use a UINavationController to push the first view controller, and then show the second one with this animation, when I tap the dismiss button(created by myself), it crashed!! So, I fixed it.
// This method doesn't suppose UINavigation model
- (id) traverseResponderChainForUIViewController {
id nextResponder = [self nextResponder];
BOOL isViewController = [nextResponder isKindOfClass:[UIViewController class]];
BOOL isTabBarController = [nextResponder isKindOfClass:[UITabBarController class]];
BOOL isNavController = [nextResponder isKindOfClass:[UINavigationController class]]; // Add this
if (isViewController && !isTabBarController && !isNavController) {
return nextResponder;
} else if(isTabBarController){
UITabBarController *tabBarController = nextResponder;
return [tabBarController selectedViewController];
} else if (isNavController)
{
// get the last but one, it should be last view controller for the showing view.
UINavigationController *nav = nextResponder;
UIViewController *lastButOne = nav.viewControllers[nav.viewControllers.count - 2];
NSLog(@"array:%@, \n%@",nav.viewControllers, lastButOne);
return lastButOne;
} else if ([nextResponder isKindOfClass:[UIView class]]) {
return [nextResponder traverseResponderChainForUIViewController];
} else {
return nil;
}
}
The core code is this:
else if (isNavController)
{
// get the last but one, it should be last view controller for the showing view.
UINavigationController *nav = nextResponder;
UIViewController *lastButOne = nav.viewControllers[nav.viewControllers.count - 2];
NSLog(@"array:%@, \n%@",nav.viewControllers, lastButOne);
return lastButOne;
}
kentnguyen commented
Please learn to format and create a proper ticket with full context (iOS version, device, specific use case)