2012-05-08 60 views
0

我在我的應用程序中使用MonoTouch.Dialog;然而,有問題的表單是使用UIViewController實現的,我添加了一個TableView(所以我也可以添加一個UIToolbar)。有沒有辦法設置ImageLoader的默認圖像?

我喜歡MonoTouch.Dialog.Utilities中的ImageLoader,並試圖在TableView的DataSource的GetCell()方法中使用它來呈現來自URL的圖像。

   var callback = new ImageLoaderCallback(controller, cell.ImageView, indexPath); // ImageLoaderCallback implements IImageUpdated 
       cell.ImageView.Image = ImageLoader.DefaultRequestImage(new Uri(picFV.Value), callback); 

的問題是,直到URL下載,爲ImageView的空間被摺疊(使文字到圖像的右側實際上是在表的左側錨定)。

我想要做的是顯示一個臨時的本地圖像,它與下載的圖像具有相同的尺寸,這樣當ImageLoader完成檢索並渲染圖像時,用戶體驗就不那麼令人震驚。

我試圖在GetCell()調用中執行以下操作... cell.ImageView.Image被設置爲一些其他圖像(下面未顯示),然後我得到一個從ImageLoader.DefaultRequestImage返回的內容的引用。

   var image = ImageLoader.DefaultRequestImage(new Uri(picFV.Value), callback); 
       callback.Image = image; 

最後一行充塞通過ImageLoader的返回到回調的狀態的圖像的參考,當ImageLoader的完成回調將替換電池的ImageView.Image(見下文):

// callback class for the MonoTouch.Dialog image loader utility 
    private class ImageLoaderCallback : IImageUpdated 
    { 
     private ListViewController controller; 
     private UIImageView imageView; 
     private NSIndexPath indexPath; 

     public ImageLoaderCallback(ListViewController c, UIImageView view, NSIndexPath path) 
     { 
      controller = c; 
      imageView = view; 
      indexPath = path; 
     } 

     public UIImage Image { get; set; } 

     void IImageUpdated.UpdatedImage(Uri uri) 
     { 
      if (uri == null) 
       return; 
      if (Image != null) 
       imageView.Image = Image; 
      // refresh the display for the row of the image that just got updated 
      controller.TableView.ReloadRows(new NSIndexPath [] { indexPath }, UITableViewRowAnimation.None);     
     } 
    } 

然而,這是行不通的,因爲看起來ImageViewer需要在TableView試圖呈現ImageView時被TableView「拉」(即ImageLoader回調從來沒有被調用,因爲沒有人使用URL)。

我該如何完成這種情況?

謝謝!

回答

相關問題