【发布时间】:2016-03-28 04:00:00
【问题描述】:
我启动了一个新的 Xamarin.iOS 项目,但我无法让 MvxImageViewLoader 正常工作。我添加了最新的 DownloadCache、File 和 Json 插件(4.1 版)并在我的安装文件中进行了配置:
protected override void AddPluginsLoaders (MvxLoaderPluginRegistry registry)
{
registry.AddConventionalPlugin<MvvmCross.Plugins.DownloadCache.iOS.Plugin>();
registry.AddConventionalPlugin<MvvmCross.Plugins.File.iOS.Plugin>();
base.AddPluginsLoaders (registry);
}
protected override void InitializeLastChance ()
{
MvvmCross.Plugins.DownloadCache.PluginLoader.Instance.EnsureLoaded();
MvvmCross.Plugins.File.PluginLoader.Instance.EnsureLoaded();
MvvmCross.Plugins.Json.PluginLoader.Instance.EnsureLoaded();
base.InitializeLastChance ();
}
在自定义 MvxTableViewCell 中,我正在尝试绑定图像:
public partial class MyTableViewCell : MvxTableViewCell
{
public static readonly NSString Key = new NSString ("MyTableViewCell");
public static readonly UINib Nib;
private readonly MvxImageViewLoader _imageViewLoader;
static MyTableViewCell ()
{
Nib = UINib.FromName ("MyTableViewCell", NSBundle.MainBundle);
}
public MyTableViewCell (IntPtr handle) : base (handle)
{
_imageViewLoader = new MvxImageViewLoader(() => imgLarge);
this.DelayBind (() => {
var set = this.CreateBindingSet<MyTableViewCell, MyViewModel>();
set.Bind (_imageViewLoader).To (vm => vm.ImageUrlLarge);
set.Apply();
});
}
}
应用程序输出中的相关错误:
mvx: Diagnostic: 366.64 failed to download image http://3.bp.blogspot.com/-2-9DK3D-bo8/T-g6U58ZU_I/AAAAAAAADpQ/NKEmG72Hl0I/s1600/Funny_Hamster_04.jpg : TypeLoadException: Could not load type 'MvxImageCache`1' from assembly ‘…/MvvmCross.Plugins.DownloadCache.dll'.
.....
at MvvmCross.Plugins.DownloadCache.MvxDynamicImageHelper`1+<RequestImageAsync>d__29[T].MoveNext () [0x001a7] in C:\vcs\git\MvvmCross-Plugins\DownloadCache\MvvmCross.Plugins.DownloadCache\MvxDynamicImageHelper.cs:135
查看该行的错误和源代码,DownloadCache 插件似乎无法解析 ImageCache:
var cache = Mvx.Resolve<IMvxImageCache<T>>();
我没有注册我应该注册的东西吗?这可能是最新版本的错误吗?我在网上看到的所有教程、问题等都是针对 3.X 版本的。有没有人用 4.X 获得了 DownloadCache 插件?
更新 我创建了一个新的 MvvmCross 解决方案来展示这个问题。您可以在此处重现该问题: https://github.com/ogoldfinger/MvvmCrossDownloadCacheTest
【问题讨论】:
-
执行 Mvx.Resolve 时异常告诉你什么?
-
无法从程序集“...MvvmCross.Plugins.DownloadCache.dll”加载类型“MvxImageCache`1”
-
肯定还有更多,比如内部异常或其他。
-
粘贴整个应用程序输出会有帮助吗?我从上面的堆栈跟踪中遗漏的唯一部分与此有关:
MvvmCross.Platform.IoC.MvxSimpleIoCContainer.InternalTryResolve -
你是否引用了为 IOS 而不是核心项目的包,如果有的话?你有 MvxImageCache 的 MvxLoaderPluginBootstrapAction 吗?我只是在这里猜测,但我认为这两个很容易错过
标签: xamarin xamarin.ios mvvmcross