Basically, what you do in the code above is creating ViewController A, then ViewControllerB, then another ViewController A, and then another ViewController B, and then another ViewController A, and then another ViewController B.
What you have to do is start with ViewController A, create a ViewController B, and then go back to ViewController A, just close Viewcontroller B.
Read this blog for advice on how to do this in a simple way, which I explained.
Now there is a possibility that using this method can cause some problems, and they are more likely to happen only when you want to do a little more than just close the current ViewController. Apple does state in its docs:
“When it comes time to reject the presented view controller, the preferred approach is to allow the view manager to reject it. In other words, when possible, the same view controller that the view controller introduced should also take responsibility for dismissal. Despite that there are several methods for notifying the presentation view manager that its submitted view controller should be rejected, prefer The final method is delegation.
Now, as @LeoNatan's answer said, this can be bad practice using [self dismissViewControllerAnimated:completion: And the paragraph above, why, I think, he said it was a bad idea.
It is really good practice to learn to do this in both directions. And although my answer is a quick way, it is also a little dirtier.
source share