2016-11-10 1 views
0

URL이 헤더와 함께 다운로드되는 이미지가있는 셀이있는 UICollectionView가 있습니다. 나는 다음과 같이한다 : -SDWebImageDownloader가 포함 된 UICollectionView의 스크롤 이미지로드 및로드 Xamarin

internal void UpdateCell(ProfileValues mdata) 
     { 


      var mUrl = "someurl"; 

    var manager = SDWebImageManager.SharedManager; 
    manager.ImageCache.MaxCacheAge = 86400; 
      SDWebImageDownloader mDownloader = manager.ImageDownloader; 

      var authToken = "SomeToken""; 


      mDownloader.SetHttpHeaderValue(authToken, "Authorization"); 
      mDownloader.SetHttpHeaderValue("application/json; odata=verbose", "Accept"); 
      mDownloader.SetHttpHeaderValue("f", "X-FORMS_BASED_AUTH_ACCEPTED"); 


      try 
      { 
       mDownloader.DownloadImage(
       url: new NSUrl(mUrl), 
    options: SDWebImageDownloaderOptions.ProgressiveDownload, 
       progressBlock: (receivedSize, expectedSize) => 
       { 
        // Track progress... 
       }, 
       completedBlock: (image, data, error, finished) => 
       { 

        if (image != null && finished) 
        { 
         InvokeOnMainThread(() => 
         { 

          this.imgProfilePic.Image = image; 
         }); 

        } 
        if (error != null) 
        { 
         InvokeOnMainThread(() => 
         { 
          this.imgProfilePic.Image = errorImage; 
          this.imgProfilePic.BackgroundColor = UIColor.FromRGB(52, 31, 71); 
          //this.imgProfilePic.Layer.CornerRadius = this.imgProfilePic.Frame.Size.Width/2; 
          this.imgProfilePic.ClipsToBounds = true; 
          this.imgProfilePic.Layer.BorderWidth = 3.0f; 
          this.imgProfilePic.Layer.BorderColor = UIColor.White.CGColor; 
         }); 
        } 
       } 


      ); 
      } 
      catch (Exception ex) 
      { 
      } 
     } 

그러나 모든 스크롤마다 셀이 다시로드되고 이미지가 매번 다운로드된다. 스크롤 할 때 캐시에서 이미지를 캐싱하고 이미지를로드하려면 어떻게합니까? 어떤 도움을 주셔서 감사합니다.

답변

0

사용 FFImageLoading 패키지는 응답을 이미지의

var cachedImage = new CachedImage() { 
    HorizontalOptions = LayoutOptions.Center, 
    VerticalOptions = LayoutOptions.Center, 
    WidthRequest = 300, 
    HeightRequest = 300, 
    CacheDuration = TimeSpan.FromDays(30), 
    DownsampleToViewSize = true, 
    RetryCount = 0, 
    RetryDelay = 250, 
    TransparencyEnabled = false, 
    Source = "http://loremflickr.com/600/600/nature?filename=simple.jpg", 
    CacheKeyFactory = new CustomCacheKeyFactory(), 
}; 
+0

감사 클래스 cachedImage 장소를 사용 &. 요청과 함께 일부 헤더를 전달해야합니다. 어떻게해야합니까? –

+0

이미지 URL로로드 한 헤더를 표시하고 싶습니까? 특정 이미지의 파일 이름과 비슷합니까? – imrohit

+0

아니요. 이미지를 다운로드 할 때 url을 다운로드하여 인증 토큰을 전달하고 싶습니다. –