Cancel ItemSelected Event in TabbarRenderer Xamarin.iOS

I have a custom tabbar renderer for iOS in a Xamarin.Forms app. In certain cases, I need to stop the ItemSelected event. Essentially, if the user taps the item on the tabbar, I need to perform a custom action and NOT navigate.

It seems that the ItemSelectedevent is too late to do this. I know that there is a ShouldShowViewController method on the UITabbarController, but this has been abstracted away but the TabbarRenderer.

How can I achieve this?

Answers

  • ColeXColeX Member, Xamarin Team Xamurai
    edited November 2018
    [assembly:ExportRenderer(typeof(TabbedPage),typeof(MyTabRenderer))]
    namespace FormsApp.iOS
    {
        class MyTabRenderer : TabbedRenderer
        {public override void ViewDidLoad()
            {
                base.ViewDidLoad();
    
                this.ShouldSelectViewController += (tabBarController, viewController) =>
                {
                    //perform a custom action
                    return false;
                };
            }
        }
    }
    
Sign In or Register to comment.