如果同時給一個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]; }];