Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
覆盖Xamarin.IOS中的后退按钮导航_Ios_Xamarin.ios - Fatal编程技术网

覆盖Xamarin.IOS中的后退按钮导航

覆盖Xamarin.IOS中的后退按钮导航,ios,xamarin.ios,Ios,Xamarin.ios,我试图使用Xamarin.IOS框架覆盖IOS的默认后退按钮行为。 我的ViewController中有一个对象堆栈,我的要求是,当用户按back键导航到上一个ViewController时,我将仅在堆栈为空时导航,否则我将留在该屏幕(ViewController)。 为此,我尝试了几件事,比如覆盖ViewWillEnglish并将PopViewController设置为false,但我无法做到这一点。请导游 public override void ViewWillDisappear(bool

我试图使用Xamarin.IOS框架覆盖IOS的默认后退按钮行为。 我的ViewController中有一个对象堆栈,我的要求是,当用户按back键导航到上一个ViewController时,我将仅在堆栈为空时导航,否则我将留在该屏幕(ViewController)。 为此,我尝试了几件事,比如覆盖ViewWillEnglish并将PopViewController设置为false,但我无法做到这一点。请导游

public override void ViewWillDisappear(bool animated)
    {
        Stack<Object> st = vPage.uContentStack;
        if (st.Count != 0)
        {
            Object pop_obj = st.Pop();
            if (st.Count != 0)
            {
                NavigationController.PopViewController(false);// Here trying to stop navigating back
                Object peek_obj = st.Peek();
                vPage.ContentUpdateOnBackPress(pop_obj, peek_obj);
            }
            else
            {
                NavigationController.PopViewController(true);
            }

        }
        else
        {
            NavigationController.PopViewController(true);
        }
        base.ViewWillDisappear(animated);
    }
公共覆盖无效视图将消失(bool动画)
{
Stack st=vPage.uContentStack;
如果(标准计数!=0)
{
对象pop_obj=st.pop();
如果(标准计数!=0)
{
NavigationController.PopViewController(false);//此处尝试停止向后导航
对象peek_obj=st.peek();
vPage.ContentUpdateOnBackPress(pop_obj,peek_obj);
}
其他的
{
NavigationController.PopViewController(true);
}
}
其他的
{
NavigationController.PopViewController(true);
}
基本视图将消失(动画);
}

您可以在特定的视图控制器中自定义导航栏

public override void ViewWillAppear(bool animated)
    {
        base.ViewWillAppear(animated);
       
        NavigationController.NavigationBar.Hidden = true;
        double height = IsiphoneX();
        UIView backView = new UIView()
        {
            BackgroundColor = UIColor.White,
            Frame = new CGRect(0, 20, UIScreen.MainScreen.Bounds.Width, height),
        };
        UIButton backBtn = new UIButton()
        {
            Frame = new CGRect(20, height - 44, 40, 44),
            Font = UIFont.SystemFontOfSize(18),
        };
        backBtn.SetTitle("<", UIControlState.Normal);
       // backBtn.SetBackgroundImage(UIImage.FromBundle("xx.png"),UIControlState.Normal); or you can set image here 
        backBtn.SetTitleColor(UIColor.FromRGB(60,140,250), UIControlState.Normal);
        backBtn.AddTarget(this, new Selector("GoBack"), UIControlEvent.TouchUpInside);
        UILabel titleLabel = new UILabel()
        {
            Frame = new CGRect(UIScreen.MainScreen.Bounds.Width / 2 - 75, 0, 150, height),
            Font = UIFont.SystemFontOfSize(20),
            Text = "xxx",
            TextAlignment = UITextAlignment.Center,
            TextColor = UIColor.Black,
            Lines = 0,
        };
        UILabel line = new UILabel()
        {
            Frame = new CGRect(0, height, UIScreen.MainScreen.Bounds.Width, 0.5),
            BackgroundColor = UIColor.Black,
        };

        backView.AddSubview(backBtn);
        backView.AddSubview(titleLabel);
        backView.AddSubview(line);
        View.AddSubview(backView);
    }
    double IsiphoneX()
    {
        double height = 44;
        if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
        {
            if (UIApplication.SharedApplication.Delegate.GetWindow().SafeAreaInsets.Bottom > 0.0)
            {
                height = 64;
            }
        }
        return height;
    }
    [Export("GoBack")]
    void GoBack()
    {
       //handle logic here
    }
    public override void ViewWillDisappear(bool animated)
    {
        base.ViewWillDisappear(animated);

        NavigationController.NavigationBar.Hidden = false;
    }
public override void视图将出现(bool动画)
{
基本视图将显示(动画);
NavigationController.NavigationBar.Hidden=true;
双倍高度=IsiphoneX();
UIView backView=新UIView()
{
BackgroundColor=UIColor.White,
帧=新的CGRect(0,20,UIScreen.MainScreen.Bounds.Width,height),
};
UIButton backBtn=新建UIButton()
{
框架=新的CGRect(20,高度-44,40,44),
Font=UIFont.SystemFontOfSize(18),
};

backBtn.SetTitle(“谢谢..但是我在这一行”backBtn.AddTarget(“这个,新选择器(“GoBack”)”上得到了错误。说找不到带参数的选择器。有什么建议吗?使用ObjRuntime添加行
;使用确切的代码添加行。
。将错误作为“NSInvalidArgumentException原因:无法识别的选择器发送到实例”“在线”如果(UIApplication.SharedApplication.Delegate.GetWindow().SafeAreaInsets.Bottom>0.0)它在我这方面工作正常。你能分享你的样本吗?这样我就可以直接在我这方面测试它了。