如何在MvvmCross中指定要作为模式推送的视图? [英] How do I specify a view to be pushed as Modal in MvvmCross?
问题描述
我在使用MvvmCross框架的MonoTouch应用程序中有一个视图,希望显示模态(NavigationController.PresentModalViewController).
I have a view in a MonoTouch app using MvvmCross framework that I would like displayed Modal (NavigationController.PresentModalViewController).
推荐答案
MvvmCross的前提是所有ViewModels都是普通页面"-因此在iOS/MonoTouch中,这意味着使用UINavigationController呈现的UIViewControllers.
MvvmCross starts from the premise that all ViewModels are just "normal pages" - so in iOS/MonoTouch that means UIViewControllers presented using a UINavigationController.
要离开此前提-转到选项卡式显示,模式显示,拆分控制器,弹出窗口等-然后可以在MonoTouch应用程序中调整Presenter逻辑.
To move away from this premise - towards tabbed displays, modal displays, split controllers, popups, etc - then you can adjust the Presenter logic within your MonoTouch app.
演示者的工作是实施:
public interface IMvxTouchViewPresenter
{
void Show(MvxShowViewModelRequest view);
void Close(IMvxViewModel viewModel);
void CloseModalViewController();
void ClearBackStack();
bool PresentModalViewController(UIViewController controller, bool animated);
void NativeModalViewControllerDisappearedOnItsOwn();
}
在AppDelegate构造中选择了用于您的应用的演示者-例如看看 TwitterSearch 为iPhone和iPad构建不同的演示者.
The presenter used for your app is selected in AppDelegate construction - e.g. see how the TwitterSearch builds different presenters for iPhone and iPad.
Fortunately, for simple Modal support, one of the standard presenters available is MvxModalSupportTouchViewPresenter.cs
此演示者希望查看所呈现的视图是否具有IMvxModalTouchView
标记界面-它测试view is IMvxModalTouchView
.如果存在此界面,那么它将对视图使用模式表示,而不是常规导航".
This presenter looks to see if the view being presented has the IMvxModalTouchView
marker interface - it tests view is IMvxModalTouchView
. If this interface is present, then it uses modal presentation for the view instead of "normal navigation".
要使用此功能,请将您的AppDelegate代码更改为以下内容:
To use this, change your AppDelegate code to something:
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
window = new UIWindow(UIScreen.MainScreen.Bounds);
// initialize app for single screen iPhone display
var presenter = new MvxModalSupportTouchViewPresenter(this, window);
var setup = new Setup(this, presenter);
setup.Initialize();
// start the app
var start = this.GetService<IMvxStartNavigation>();
start.Start();
window.MakeKeyAndVisible();
return true;
}
然后将标记界面添加到您的模式视图中:
Then add the marker interface to your modal View(s):
public class MyView : MvxBindingTouchViewController<MyViewModel>, IMvxModalTouchView
{
// ....
}
这篇关于如何在MvvmCross中指定要作为模式推送的视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!