Dismiss View Controller unexpected behaviour

2019-09-15 02:52发布

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条回答
smile是对你的礼貌
2楼-- · 2019-09-15 03:06

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.

查看更多
Emotional °昔
3楼-- · 2019-09-15 03:16

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.

查看更多
做自己的国王
4楼-- · 2019-09-15 03:29

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

查看更多
你好瞎i
5楼-- · 2019-09-15 03:29

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

查看更多
登录 后发表回答