假设我有一个 ViewModel:
public class MyViewModel : MvxViewModel
{
public override void Start()
{
base.Start();
//Important things would happen here!
}
}
当我现在ShowViewModel<MyViewModel>();
从任何其他 ViewModel 使用时,它会从 MyViewModel进入被覆盖的Start()方法。
但是,当我从后退/返回按钮导航时,它不会进入。
BackButton 是这样构建的:
class MyPresenter : MvxModalSupportTouchViewPresenter
{
public INMobileAdminPresenter(UIApplicationDelegate applicationDelegate, UIWindow window)
: base(applicationDelegate, window)
{
}
protected override UINavigationController CreateNavigationController (UIViewController viewController)
{
var toReturn = base.CreateNavigationController (viewController);
toReturn.NavigationBarHidden = false;
return toReturn;
}
}
在 AppDelegate.cs 中,我正在执行以下操作:
[Register("AppDelegate")]
public partial class AppDelegate : MvxApplicationDelegate
{
UIWindow window;
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
window = new UIWindow(UIScreen.MainScreen.Bounds);
//var presenter = new MvxTouchViewPresenter(this, window);
var presenter = new MyPresenter(this, window); //Here my Presenter instead of the standard one
//and so far....
}
}
每次从 ViewModel进入Start()
方法对我来说很重要——无论我现在使用的是 ShowViewModel 还是导航来自 BackButton,因为我在那里订阅了一些相关的 Eventtaggregationmessages。
任何帮助表示赞赏!