Question: I have an issue with the `presentViewController`function.

I have a login menu (A) and a button who display a login form (B). On success login, I present a third view with `self.presentViewController` (C).

Login menu (A) -> Login form (B) -> Content (C)

It's work, I can present the third view (C) but the login menu (A) is always visible (I can see it in UI Debug mod).

So, how to close the A ViewController?

Answer: 
If we consider the **presentVieController** mechanism, this is not a problem or bug. Still if you feel that you don not want your previous controller's remain in Hierarchy, Then you have to change the flow.

Currently your flow is :

A -> RootViewController.
B -> LoginScreen
C -> Container

I would suggest to refer below answer for best practise.

[Best practices for Storyboard login screen, handling clearing of data upon logout](https://stackoverflow.com/questions/19962276/best-practices-for-storyboard-login-screen-handling-clearing-of-data-upon-logou)

if you give thoughts on handling the flow, you can solve your problem. here are my suggestions

**Suggestions** :

1. You set **C** as a rootController, In **C's ViewDidLoad** , you check weather User is logged in or not, If user is not logged in, you can present **A** , And From there you can present **B**. Once you successfully get logged in, you can dismiss **A** and **B** And refresh your rootController **C** as per logged user values.

To dismiss multiple view controller, you can try below code

```
-(void)dismissModalStack {
    UIViewController *vc = self.presentingViewController;
    while (vc.presentingViewController) {
        vc = vc.presentingViewController;
    }
    [vc dismissViewControllerAnimated:YES completion:NULL];
}

```

2. You can also use the **ContainerView** mechanism, You set **C** as rootController, And in **C** , you take an **ContainerView** In which you can show the **A** And **B** and after login, you can remove them and refresh **C**.

Hope it Helps!
I think this tutorial has your answer <https://www.youtube.com/watch?v=WIaRs2d6Xm0>