解除View Controller意外行为

时间:2017-02-02 05:48:11

标签: ios swift uinavigationcontroller

我面临着关于现在解雇 ViewController的奇怪问题。

例如: -

我在ViewController A,然后我推送到B

所以在导航控制器堆栈中我们有[A,B]

现在,如果我在B上呈现任何视图控制器(如MFMailComposeViewController)

然后在发送邮件或删除草稿后,它会关闭MFMailComposeViewController,它会重定向到A而不是B.

我已就这方面进行了研究,但无法找到任何替代方案。

4 个答案:

答案 0 :(得分:0)

如果你在ViewControllerB中的MFMailComposeViewControllerDelegate的didFinishWithResult方法中调用了Popviewcontroller方法,那么它就有可能。 相反,你在didFinishWithResult方法调用中避免使用PopViewController方法调用。

答案 1 :(得分:0)

希望这会有所帮助。在A - >之间切换时使用它B.

```让storyboard = UIStoryboard(名称:" Main",bundle:nil)

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

UIApplication.shared.delegate?.window ??。RootViewController的? = desiredViewController```

答案 2 :(得分:0)

尝试这样从B

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

您可能已经使用过

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

希望这有帮助

答案 3 :(得分:0)

你好,你可以这样做,当你在发送邮件或删除草稿后解雇它会解雇MFMailComposeViewController然后你可以检查ViewController_Identifier,如果它是'A_Screen'然后避免它或逃避它。否则,如果是'B-Screen'则导航到该视图控制器。

使用此逻辑可以根据需要进行导航。

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)
            }

确保您已为ViewControllers设置了identifierID。

希望它对你有所帮助。