Xamarin.ios 在MonoTouch上集成第三方控制器和MVVMCross
我想使用已经从UIViewController()继承的第三方视图控制器,如何将其与MVVMCross集成 我可以直接获取源代码并将其更改为从MvxViewController继承,但我想我会在其他库中遇到这种情况Xamarin.ios 在MonoTouch上集成第三方控制器和MVVMCross,xamarin.ios,mvvmcross,Xamarin.ios,Mvvmcross,我想使用已经从UIViewController()继承的第三方视图控制器,如何将其与MVVMCross集成 我可以直接获取源代码并将其更改为从MvxViewController继承,但我想我会在其他库中遇到这种情况 我需要实现MvxViewController的所有接口吗?IMvxTouchView?IMvxEventSourceViewController?您可以使用下面这样的自定义视图演示器,这几乎是我的应用程序使用滑动导航直接提供的 public class Presenter :
我需要实现MvxViewController的所有接口吗?IMvxTouchView?IMvxEventSourceViewController?您可以使用下面这样的自定义视图演示器,这几乎是我的应用程序使用滑动导航直接提供的
public class Presenter
: IMvxTouchViewPresenter
{
private readonly MvxApplicationDelegate applicationDelegate;
private readonly UIWindow window;
private SlideoutNavigationController slideNavigationController;
private IMvxTouchViewCreator viewCreator;
public Presenter(MvxApplicationDelegate applicationDelegate, UIWindow window)
{
this.applicationDelegate = applicationDelegate;
this.window = window;
this.slideNavigationController = new SlideoutNavigationController();
this.slideNavigationController.SlideWidth = 200f;
this.window.RootViewController = this.slideNavigationController;
}
public async void Show(MvxViewModelRequest request)
{
var creator = Mvx.Resolve<IMvxTouchViewCreator>();
if (this.slideNavigationController.MenuView == null)
{
// TODO: MAke this not be sucky
this.slideNavigationController.MenuView = (MenuView)creator.CreateView(new MenuViewModel());
((MenuView) this.slideNavigationController.MenuView).MenuItemSelectedAction = this.MenuItemSelected;
}
var view = creator.CreateView(request);
this.slideNavigationController.TopView = (UIViewController)view;
}
public void ChangePresentation(MvxPresentationHint hint)
{
Console.WriteLine("Change Presentation Requested");
}
public bool PresentModalViewController(UIViewController controller, bool animated)
{
Console.WriteLine("Present View Controller Requested");
return true;
}
public void NativeModalViewControllerDisappearedOnItsOwn()
{
Console.WriteLine("NativeModalViewControllerDisappearedOnItsOwn");
}
private void MenuItemSelected(string targetType, string objectId)
{
var type = Type.GetType(string.Format("App.Core.ViewModels.{0}ViewModel, AppCore", targetType));
var parameters = new Dictionary<string, string>();
parameters.Add("objectId", objectId);
this.Show(new MvxViewModelRequest { ViewModelType = type, ParameterValues = parameters });
}
}
公共类演示者
:IMvxTouchViewPresenter
{
专用只读MVXApplicationLegate applicationLegate;
私有只读UIWindow窗口;
专用滑出导航控制器滑出导航控制器;
私有IMvxTouchViewCreator viewCreator;
公共演示者(MVXApplicationLegate applicationLegate,UIWindow)
{
this.applicationelegate=applicationelegate;
this.window=窗口;
this.slideNavigationController=新的SlideoutNavigationController();
this.slideNavigationController.SlideWidth=200f;
this.window.RootViewController=this.slideNavigationController;
}
公共异步无效显示(MvxViewModelRequest请求)
{
var creator=Mvx.Resolve();
if(this.slideNavigationController.MenuView==null)
{
//TODO:别让这太差劲了
this.slideNavigationController.MenuView=(MenuView)creator.CreateView(新的MenuViewModel());
((MenuView)this.slideNavigationController.MenuView).MenuItemSelectedAction=this.MenuItemSelected;
}
var view=creator.CreateView(请求);
this.slideNavigationController.TopView=(UIViewController)视图;
}
公共void changepression(mvxpressionhint)
{
Console.WriteLine(“请求更改演示文稿”);
}
public bool PresentModalViewController(UIViewController控制器,bool动画)
{
Console.WriteLine(“请求当前视图控制器”);
返回true;
}
public void NativeModalViewController在其自身()中出现
{
Console.WriteLine(“NativeModalViewControllerDisappearedOnItsOwn”);
}
private void MenuItemSelected(字符串targetType,字符串objectId)
{
var type=type.GetType(string.Format(“App.Core.ViewModels.{0}ViewModel,AppCore”,targetType));
var参数=新字典();
参数。添加(“objectId”,objectId);
Show(新的MvxViewModelRequest{ViewModelType=type,ParameterValues=parameters});
}
}
对于这种特殊情况,您实际上不想进行任何数据绑定,因此只需使用自定义演示程序即可-例如,请参阅@Blounty的答案,或查看此项目演示-
如果您确实需要转换第三方
ViewController
基类以支持数据绑定,那么最简单的方法就是您所猜测的:
- 从它们继承以提供一个
-ViewControllerEventSource
- 从
-ViewController继承以添加Mvx绑定上下文EventSource
MvvmCross
本身扩展UIViewController
、UITableViewController
、UITableViewController等以提供数据绑定的方法
例如,请参见:
- 扩展UIViewController以提供事件源-
- 扩展事件源ViewController以提供绑定上下文-
在Android中,活动基类也遵循类似的过程-请参见我认为这是集成SlidenavigationController的最佳方式,我甚至没有想到过这种方式。我认为这完全涵盖了一般答案。