猿问

如何检查当前的ViewController是否被推送或显示

我是Xamarin的新手。我进行了很多搜索,以了解我的ViewController是推送还是显示。因此,我将弹出它或相应地将其关闭,但失败了。


阿晨1998
浏览 159回答 2
2回答

慕无忌1623718

您只需要检查Navigation Stack中是否存在当前的viewcontroller 。解决方案if(this.NavigationController == null){    this.DismissViewController(true, null);}else{    this.NavigationController.PopViewController(true);}

qq_花开花谢_0

您可以使用以下方法private static UIViewController GetController(){    var vc = UIApplication.SharedApplication.KeyWindow.RootViewController;    while (vc.PresentedViewController != null  && vc.PresentedViewController.ToString().Contains("Xamarin_Forms_Platform_iOS_ModalWrapper"))        vc = vc.PresentedViewController;    return vc;}如果返回的结果不为null,则表示您的堆栈中存在Present控制器
随时随地看视频慕课网APP
我要回答