在MVVMCross中从4.4迁移到5.7时出现CustomPresenter错误

时间:2019-09-20 15:14:59

标签: c# xamarin xamarin.ios mvvmcross

你好stackoverflowers, 我正在使用MVVMCross和Xamarin针对iOS和Android构建的项目。我发现该项目使用了相当老版本的MVVMCross(4.4.0),并且我试图将其升级到当前版本(6.4)。我认为先升级到5.7是一个好主意,稍后,当我将导航切换到新表格等时,我将升级到6 ++。我已经成功地将Android版本运行到5.7,但是iOS版本使用了customPresenter,我不太了解如何转换为5.1中引入的新Presenter。我认为我的自定义演示者是基于https://github.com/MvvmCross/MvvmCross-Samples/tree/master/XPlatformMenus/XPlatformMenusTabs.iOS的,这已经有一段时间没有更新了。

在子类MvxIosViewPresenter的MvxTabPresenter中,show函数不再可重写。另外,IMvxModalIosView似乎不再存在。

public override void Show(IMvxIosView view)
        {
            if (view is IMvxModalIosView)
            {
                if (this._currentModalViewController != null)
                {
                    return;
                }

                var currentModalViewController = view as MvxViewController;
                this._currentModalViewController = currentModalViewController;
                currentModalViewController.ModalPresentationStyle = UIModalPresentationStyle.Popover;
                CurrentTopViewController.AddChildViewController(currentModalViewController);
                currentModalViewController.View.Frame = CurrentTopViewController.View.Bounds.Inset(10, 10);
                currentModalViewController.View.Alpha = 0;
                CurrentTopViewController.View.Add(currentModalViewController.View);
                currentModalViewController.DidMoveToParentViewController(CurrentTopViewController);

                UIView.Animate(0.25, () =>
                {
                    currentModalViewController.View.Alpha = 1;
                });


                //this.PresentModalViewController(currentModalViewController, true);
                return;
            }

            if (view is HomeView)
            {
                if (this.CurrentTopViewController is MvxTabBarViewController)
                {
                    TabBarPresenter.SelectedIndex = 0;
                    return;
                } 


 public override void CloseModalViewController()
        {
            if (this._currentModalViewController != null)
            {
                this._currentModalViewController.DismissModalViewController(true);
                _currentModalViewController.WillMoveToParentViewController(null);
                _currentModalViewController.View.RemoveFromSuperview();
                _currentModalViewController.RemoveFromParentViewController();
                this._currentModalViewController = null;
                return;
            }

            base.CloseModalViewController();
        }

            }

这也不再是超类所能覆盖的。

关于如何处理此问题的任何建议?

亲切的问候, V

1 个答案:

答案 0 :(得分:1)

您可能会在MvxIosViewPresenter中看到,现在mvx属性已注册到应调用的操作中。

因此,首先,您应该继承MvxIosViewPresenter。然后,对于模式,您应该覆盖ShowModalViewController

我建议您阅读仓库中的docsMvxIosViewPresenterMvxAttributeViewPresenter 文件,以了解其工作原理。

HIH