Dismiss View Controller unexpected behaviour

人走茶凉 提交于 2020-01-07 03:12:13

问题


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.


回答1:


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.




回答2:


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 ```




回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/41995035/dismiss-view-controller-unexpected-behaviour

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!