2

我在非常简单的情况下使用MvxImageViewLoader 。

ViewDidLoad 上

        var pnlBackImage = new UIImageView(new RectangleF(0, 0, pnlBack.Frame.Width, pnlBack.Frame.Height));
        Add(pnlBackImage);
        pnlBackImageLoader = new MvxImageViewLoader(() => pnlBackImage);

        ...

        set.Bind(pnlBackImageLoader).To(x => x.UserBackgroundUrl);

其中 UserBackgroundUrl 是一个常见的字符串属性

但是在set.Apply()上,我在日志中看到以下内容并且图像未加载

2013-06-24 13:51:26.999 SPBTouch[446:21b03] MvxBind: Error:   2.78 Problem seen during binding execution for from UserBackgroundUrl to ImageUrl - problem TargetInvocationException: Exception has been thrown by the target of an invocation.
      at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x000d9] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:236 
  at System.Reflection.MonoProperty.SetValue (System.Object obj, System.Object value, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] index, System.Globalization.CultureInfo culture) [0x00064] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Reflection/MonoProperty.cs:353 
  at System.Reflection.PropertyInfo.SetValue (System.Object obj, System.Object value, System.Object[] index) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Reflection/PropertyInfo.cs:93 
  at Cirrious.MvvmCross.Binding.Bindings.Target.MvxPropertyInfoTargetBinding.SetValue (System.Object value) [0x00000] in <filename unknown>:0 
  at Cirrious.MvvmCross.Binding.Bindings.MvxFullBinding.UpdateTargetFromSource (Boolean isAvailable, System.Object value) [0x00000] in <filename unknown>:0 
InnerException was NullReferenceException: Object reference not set to an instance of an object
      at Cirrious.MvvmCross.Binding.Views.MvxBaseImageViewLoader`1[MonoTouch.UIKit.UIImage].set_ImageUrl (System.String value) [0x00000] in <filename unknown>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x000c0] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:228 

我什至将图像加载器甚至图像面板定义为视图字段,但仍然没有运气。什么会导致这个问题?

谢谢你。

4

2 回答 2

6

The inner exception error you've listed is:

NullReferenceException: Object reference not set to an instance of an object at Cirrious.MvvmCross.Binding.Views.MvxBaseImageViewLoader`1[MonoTouch.UIKit.UIImage].set_ImageUrl (System.String value) [0x00000] in :0

I guess the thing that would cause a NullReferenceException in the set of:

    public string ImageUrl
    {
        get { return _imageHelper.ImageUrl; }
        set { _imageHelper.ImageUrl = value; }
    }

is if _imageHelper is null

Looking in MvxBaseImageViewLoader.cs#L31 this can happen if this error message is displayed Unable to resolve the image helper - have you referenced and called EnsureLoaded on the DownloadCache plugin?

Is this error message displayed? If so, is the DownloadCache plugin (and it's dependent plugin File) loaded in your application?


If this doesn't help, try comparing your app so some of the apps in N+1. Successful use of the image views is covered in several of N+1 videos - http://mvvmcross.wordpress.com/ - e.g. N=2 or N=3

于 2013-06-24T11:22:02.653 回答
3

当我按照MvvmCross CollectionView 示例的教程遇到此问题中提到的相同错误(异常)时,我来到这里。我发现如果您错过注册/安装插件,您会收到此错误。我通过安装以下插件解决了错误:

安装包 MvvmCross.ITSparta.Plugin.DownloadCache

安装包 MvvmCross.ITSparta.Plugin.File

安装这些插件后,会在您的 UI 项目 (iOS/Android) 中创建新文件并注册这些插件。因此,您不会收到此错误。

于 2016-02-21T08:04:22.530 回答