I need to have control of this method so that I can make a change in my app. But I couldn't make this implementation work, can anyone help?
Here is the Custom Renderer of my TabbedPage:
public class MainTabbedPageRenderer : TabbedRenderer, IUITabBarControllerDelegate
{
[Export("tabBarController:shouldSelectViewController:")]
public bool ShouldSelectViewController(UITabBarController tabBarController, UIViewController viewController)
{
return false;
}
}
The breakpoint does not stop there at all.
I have the impression that it does not stop at breakpoint because TabBarController is always null, but the screen loads and performs navigations normally, I also could not make this TabBarController be filled.
You can click on tabbar items using this method:
[Export("tabBar:didSelectItem:")]
public void ItemSelected(UITabBar tabbar, UITabBarItem item)
{
}
I don't see where you are assigning your delegate. That is likely why it is not hit, you have not assigned the delegate to the UITabBarController (which is the base class for TabbedRenderer). Also TabbedRenderer already assigns a delegate, so you likely do not want to replace it.
That said, Xamarin.iOS actually defines a C# delegate, called UITabBarSelection
, for the ShouldSelectViewController
protocol method. And there is a property on TabbedRenderer
called ShouldSelectViewController
that allows you to set this delegate method, so you should be able to just do this:
public class MainTabbedPageRenderer : TabbedRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
this.ShouldSelectViewController = ShouldSelectViewControllerHandler;
}
bool ShouldSelectViewControllerHandler(UITabBarController tabBarController, UIViewController viewController)
{
return false;
}
}