The OnBackButtonPressed doesn't get called. I have looked at other places, the function worked on android hardware back button. I wanted to alert user to enter the pin before they can go back to previous screen. My page was not a normal page. It's a tab page.. What should I do to override the navigation back button on iOS.
You need to replace the default back button with a custom back button, Xamarin Forms’s Navigation Bar is mapped to the UINavigationBar
in iOS so you need to set custom back button to UILeftBarButtonItem
like below
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);
}
You also need to bridge between Native to Forms so that you can get a callback in your Xamarin PCL or shared project.
There is a full implementation with code in this article