Reject modal view controller stack

Given the following type of controller controller.

View controller layout

We create a stack of modal view dispatchers by first representing B on A and then representing C on B According to Apple's documentation on dismiss(animated:completion:) , calling it on A should actually reject the topmost view controller ( C in this case) in an animated manner and all intermediate view controllers without animation. However, it happens that C rejected without animation, and B rejected in an animated way.

I put up an Xcode project on GitHub that reproduces this behavior. Am I missing something or am I not understanding the documentation here?

+5
source share
3 answers

After scrambling over the network and trying out various “solutions”, it’s clear that this is a real mistake in iOS. It is present with iOS 8 ... and is still present in iOS 10. It was originally listed in iOS 8, but the solution was never tested, and Apple automatically closed the radar due to inactivity.

I filed a new radar as this directly contradicts the documentation for dismissViewController

If you consecutively represent multiple view controllers, stack the presented view controllers by calling this method (meaning - [UIViewController rejectViewControllerAnimated: completion]) on the view controller below in the stack rejects its immediate child view controller and all view controllers above this child in the stack. When this happens, only the topmost view is rejected in the animated mode; any intermediate controllers are simply removed from the stack.

Clear visualization of the problem, both expected and actual results. Sign Boris Survorov for a test project and visualization.

Expected results IOS 8 + actual results

+5
source

I had the same problem and this is what I found a viable solution. When you need to remove the entire stack, execute this code in A:

 viewControllerB.view.isHidden = true viewControllerC.dismiss(animated: true) // or viewControllerB.dismiss(animated:true) - it should produce the same result: dismiss viewControllerC dismiss(animated: false) // dismisses viewControllerB 

This should lead to the expected behavior.

+3
source

I assume your segue from A to B is also modal? In this case, the dismiss function called from A wants to reject the view that is directly above A, which is B. C just hides to show you an animated hide of B. In this sense, you cannot add browse through modal segments and reject the top using the dismiss function, as you described, if you go so far back. dismiss will work as intended if called from B to reject C though.

0
source

All Articles