Xamarin.Forms NavBar in iOS shows last page's title

Whenever I navigate to a page, NavBar title shows two texts. One on back button, the other is my page title.

It's OK if the back button shows "back" as text, but it's showing title of previous page. How do I get rid of it? (would prefer to get no text at all)

Answers

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    Take a look to navigationpage.setxxxx properties

  • DushyantBangalDushyantBangal USMember ✭✭

    @AlessandroCaliaro , already tried NavigationPage.SetBackButtonTitle(this, "mytitle");
    didnt work

  • RafaelMouraRafaelMoura BRInsider, University, Developer Group Leader ✭✭✭
    edited August 2015
    [assembly: ExportRenderer(typeof(Page), typeof(CustomNavigationRenderer))]
    namespace Project.iOS
    {
        public class CustomNavigationRenderer : PageRenderer
        {
            public CustomNavigationRenderer ()
            {
            }
    
            protected override void OnElementChanged (VisualElementChangedEventArgs e)
            {
                base.OnElementChanged (e);
            }
    
            public override void ViewWillAppear (bool animated)
            {
                base.ViewWillAppear (animated);
    
                try {
                    UIBarButtonItem backButton = new UIBarButtonItem();
                    backButton.Title = ""; //Your BackBurron Title here
                    NavigationController.NavigationBar.TopItem.BackBarButtonItem = backButton;
                } catch (Exception) {
    
                }
            }
        }
    }
    
  • DushyantBangalDushyantBangal USMember ✭✭

    Figured it out.
    You need to set NavigationPage.SetBackButtonTitle for the PREVIOUS page, and not the current page.

    So I had to set the Back button title for Page A so that it will appear on Page B's back button.

    @RafaelMoura , I didnt want to create custom renderer for every platform :wink:
    Xamarin should put better documentation for these methods.

Sign In or Register to comment.