【问题标题】:MvvmCross 4.1 - MvxImageViewLoader not workingMvvmCross 4.1 - MvxImageViewLoader 不工作
【发布时间】: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


【解决方案1】:

手动安装此 Nuget:System.Collections.Immutable

这是 DownloadCache 插件的问题,缺少对 System.Collections.Immutable 的依赖。看到这个:https://github.com/MvvmCross/MvvmCross-Plugins/issues/78

这个问题已经解决了,下次更新下载缓存包就不需要了。

【讨论】:

  • 现在尝试此操作时(即使将下载缓存插件更新到 4.1.1,我也会收到以下错误“无法安装包 'System.Resources.ResourceManager 4.0.0'。您正在尝试安装它打包到以“Xamarin.iOS,Version=v1.0”为目标的项目中,但该包不包含任何与该框架兼容的程序集引用或内容文件。”。我在这里遗漏了什么吗?
猜你喜欢
  • 2018-12-16
  • 2016-03-23
  • 2016-04-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多