2013-06-24 508 views
2

我使用MvxImageViewLoader非常簡單的情況。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 

我甚至定義的圖像加載器,甚至是圖像面板作爲查看字段,但仍然沒有運氣。什麼會導致這個問題?

謝謝。

回答

6

你所列出的內部異常的錯誤是:

的NullReferenceException:在Cirrious.MvvmCross.Binding.Views.MvxBaseImageViewLoader`1 [MonoTouch.UIKit對象引用未設置到對象 的實例。的UIImage] .set_ImageUrl(System.String值)[0x00000]在:0

我想這將在set的引起NullReferenceException的東西:

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

是,如果_imageHelper爲null

展望MvxBaseImageViewLoader.cs#L31如果顯示Unable to resolve the image helper - have you referenced and called EnsureLoaded on the DownloadCache plugin?

此錯誤消息是顯示錯誤信息,會發生這種情況?如果是這樣,請在您的應用程序中加載DownloadCache插件(以及它的相關插件File)?


如果這沒有幫助,請嘗試比較您的應用程序,以便在N + 1中對其中的一些應用程序進行比較。 N + 1個視頻中的幾個 - http://mvvmcross.wordpress.com/ - 例如N = 2或N = 3

+0

謝謝!其實就是這樣。可能,我錯過了沒有添加這些(包括「文件」)插件,但通知消息不明確。 – Agat

+0

@stuart沒有DownloadCache插件,MvxImageLoader不能工作嗎?我認爲在Android上它起作用 –

3

我來到這裏,當我遇到同樣的錯誤(例外),在這個問題中提到的跟隨教程MvvmCross CollectionView example。我發現如果你錯過了註冊/安裝你的插件,你會得到這個錯誤。我通過安裝以下插件解決錯誤:

安裝,包裝MvvmCross.ITSparta.Plugin.DownloadCache

安裝,包裝MvvmCross.ITSparta.Plugin.File

當這些插件都是安裝後,將在您的UI項目(iOS/Android)中創建新文件,並註冊這些插件。因此,你不會得到這個錯誤。