0
votes

I am facing strange issue regarding Present and Dismiss ViewController.

For e.g :-

I am at ViewController A then i push to B

So in Navigation Controller Stack we have [A,B]

Now if i present any view controller on B (Like MFMailComposeViewController)

Then after sending mail or deleting draft it dismiss the MFMailComposeViewController and it redirects to A instead of B.

I have researched regarding this but can't find any alternative.

4
Can you show the didFinishWithResult method of MFMailComposeViewControllerDelegate?Nirav D
Share the code how you are adding/removing(Push/Pop/Present/Dismiss) NavigationController,A,B and MFMailComposeViewController.Mohammad Zaid Pathan

4 Answers

0
votes

if you have called Popviewcontroller method in didFinishWithResult method of MFMailComposeViewControllerDelegate in ViewControllerB, then it could be possible. instead you avoid PopViewController method call in didFinishWithResult method call.

0
votes

Hope this helps. Use it when you switch between A -> B.

```let storyboard = UIStoryboard(name: "Main", bundle: nil)

desiredViewController = storyboard.instantiateViewController(withIdentifier: "desiredViewController")

UIApplication.shared.delegate?.window??.rootViewController? = desiredViewController ```

0
votes

try this to presented MFMailComposeViewController from B

self.navigationController?.present(MFMailComposeViewController, animated: true, completion: nil)

You might have used

self.present(MFMailComposeViewController, animated: true, completion: nil)

Hope this helps

0
votes

Hello you can do it like this, when you dismiss after sending mail or deleting draft it dismiss the MFMailComposeViewController and after that you can check the ViewController_Identifier if it is 'A_Screen' then avoid it or escape it. Else if, it is 'B-Screen' then navigate to that view controller.

Use this logic to navigate as you want.

let targetView: String! = self.restorationIdentifier
    if targetView == "A_Screen"{
                //Do nothing
            }
            else{
    let B_View = self.storyboard?.instantiateViewController(withIdentifier: "B_Screen") as! BViewController

                self.navigationController?.pushViewController(B_View, animated: true)
            }

Make sure, that you have set identifierID for your ViewControllers.

Hope it helps you.