删除导航栏中的后退箭头,保留后退按钮标题

Removing back arrow in navigation bar keeping back button title

我有 xamarin forms ios 应用程序,我需要在其中删除导航栏中的后退箭头,但应显示标题,当用户单击该后退按钮标题时,它应导航到上一个视图. 我尝试使用`

NavigationPage.SetBackButtonTitle(this, "Cancel");

NavigationPage.SetHasBackButton(this, false);

但是后退箭头还在显示,请问为什么只有文字Cancel没有<符号?

在您的 AppDelegate.cs 文件中,在 FinishedLaunching 方法中添加以下行:

UINavigationBar.Appearance.BackIndicatorImage = new UIImage();
UINavigationBar.Appearance.BackIndicatorTransitionMaskImage = new UIImage();

但是,这会为每一页删除它。如果你只想要一个页面,我建议像 EvZ 已经提到的那样:使用模态页面或找到另一种方式。

另一种方法是将上面的行设置为null,这将恢复正常的箭头。但这将意味着实现自定义渲染器、依赖服务或类似的。

我通过如下添加自定义渲染器解决了我的问题

public override void ViewWillAppear(bool animated)
{      
    base.ViewWillAppear(animated);
    this.NavigationController.TopViewController.NavigationItem.LeftBarButtonItem =new UIBarButtonItem(“Cancel”, UIBarButtonItemStyle.Plain, (sender, args) => { });      
}

去掉navigation-bar,导航处用image/header,写入image/Header 导航标题...

image onclick事件写入回写命令