我有此代码附加:OnTabbarControllerItemSelected;
到tabbarController.ViewControllerSelected
。据我了解,类似的事件也应该在以后分离。
有人可以给我建议我应该在哪里进行分离。我还应该重写此代码的Dispose方法,如果是,该怎么办?
码:
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
_page = (MainPage)e.NewElement;
}
else
{
_page = (MainPage)e.OldElement;
}
if (e.OldElement != null)
{
Xamarin.Forms.Application.Current.PropertyChanged -= Current_PropertyChanged;
return;
}
try
{
var tabbarController = (UITabBarController)this.ViewController;
if (null != tabbarController)
{
Xamarin.Forms.Application.Current.PropertyChanged += Current_PropertyChanged; //subscribe to the App class' built in property changed event
tabbarController.ViewControllerSelected += OnTabbarControllerItemSelected;
UpdateTheme();
}
}
catch (Exception exception)
{
Console.WriteLine(exception);
}
}
希望获得一些建议,以我如何以与分离
Current_PropertyChanged
方法类似的方式分离此方法。 最佳答案
您尝试过tabbarController.ViewControllerSelected -= OnTabbarControllerItemSelected;
吗?