【问题标题】:Xamarin form: How to override the OnBackButtonPressed on iOSXamarin 表单:如何在 iOS 上覆盖 OnBackButtonPressed
【发布时间】:2017-05-24 10:10:43
【问题描述】:

不会调用 OnBackButtonPressed。我看过其他地方,该功能适用​​于android硬件后退按钮。我想提醒用户输入密码,然后他们才能返回上一个屏幕。我的页面不是正常页面。这是一个标签页。我应该怎么做才能覆盖 iOS 上的导航返回按钮。

【问题讨论】:

    标签: ios xamarin navigation back-button


    【解决方案1】:

    您需要将默认后退按钮替换为自定义后退按钮,Xamarin Forms 的导航栏在 iOS 中映射到 UINavigationBar,因此您需要将自定义后退按钮设置为 UILeftBarButtonItem,如下所示

    public override void ViewWillAppear(bool animated)
    {
        var backBtn = new UIButton(UIButtonType.Custom)
        {
            // setup your custom back button with title, image etc
        }
        backBtn.TouchDown += (sender, e) =>
        {
            //Handle back click here
        };
    
        NavigationController.TopViewController.
        NavigationItem.LeftBarButtonItem = new UIBarButtonItem(backBtn);
    }
    

    您还需要在 Native 到 Forms 之间架起桥梁,以便您可以在 Xamarin PCL 或共享项目中获得回调。

    article 中有完整的代码实现

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-03
      • 1970-01-01
      • 1970-01-01
      • 2020-08-02
      • 1970-01-01
      • 2016-10-17
      • 1970-01-01
      相关资源
      最近更新 更多