SDWebImage [UIButton setImageWithURL:(NSURL *) forState:(UIControlState)] 的bug

如果同時給一個button 設置兩個狀態的網絡圖片 如下:

[button setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/images/%@.png", URL_ROOT, NORMAL_STATE]]
               forState:UIControlStateNormal];

[button setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/images/%@.png", URL_ROOT, SELECTED_STATE]]
               forState:UIControlStateSelected];
那麼設置第二張圖片時,如果第一張還沒下載完,會自動取消第一張的下載。造成第一張圖片顯示不出來。

當然這是sdWebImage的一個小bug,我臨時的處理方案如下:

[button setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/images/%@.png", URL_ROOT, NORMAL_STATE]]
               forState:UIControlStateNormal
              completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {

                  [button setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/images/%@.png", URL_ROOT, SELECTED_STATE]]
                                 forState:UIControlStateSelected];

              }];

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章