Authored by iwill

Fix issue #2001

@@ -16,10 +16,14 @@ @@ -16,10 +16,14 @@
16 16
17 static char imageURLStorageKey; 17 static char imageURLStorageKey;
18 18
19 -typedef NSMutableDictionary<NSNumber *, NSURL *> SDStateImageURLDictionary; 19 +typedef NSMutableDictionary<NSString *, NSURL *> SDStateImageURLDictionary;
20 20
21 -static inline NSNumber * backgroundImageURLKeyForState(UIControlState state) {  
22 - return @(NSUIntegerMax - state - 1); 21 +static inline NSString * imageURLKeyForState(UIControlState state) {
  22 + return [NSString stringWithFormat:@"image_%lu", (unsigned long)state];
  23 +}
  24 +
  25 +static inline NSString * backgroundImageURLKeyForState(UIControlState state) {
  26 + return [NSString stringWithFormat:@"backgroundImage_%lu", (unsigned long)state];
23 } 27 }
24 28
25 @implementation UIButton (WebCache) 29 @implementation UIButton (WebCache)
@@ -27,17 +31,17 @@ static inline NSNumber * backgroundImageURLKeyForState(UIControlState state) { @@ -27,17 +31,17 @@ static inline NSNumber * backgroundImageURLKeyForState(UIControlState state) {
27 #pragma mark - Image 31 #pragma mark - Image
28 32
29 - (nullable NSURL *)sd_currentImageURL { 33 - (nullable NSURL *)sd_currentImageURL {
30 - NSURL *url = self.imageURLStorage[@(self.state)]; 34 + NSURL *url = self.imageURLStorage[imageURLKeyForState(self.state)];
31 35
32 if (!url) { 36 if (!url) {
33 - url = self.imageURLStorage[@(UIControlStateNormal)]; 37 + url = self.imageURLStorage[imageURLKeyForState(UIControlStateNormal)];
34 } 38 }
35 39
36 return url; 40 return url;
37 } 41 }
38 42
39 - (nullable NSURL *)sd_imageURLForState:(UIControlState)state { 43 - (nullable NSURL *)sd_imageURLForState:(UIControlState)state {
40 - return self.imageURLStorage[@(state)]; 44 + return self.imageURLStorage[imageURLKeyForState(state)];
41 } 45 }
42 46
43 - (void)sd_setImageWithURL:(nullable NSURL *)url forState:(UIControlState)state { 47 - (void)sd_setImageWithURL:(nullable NSURL *)url forState:(UIControlState)state {
@@ -66,11 +70,11 @@ static inline NSNumber * backgroundImageURLKeyForState(UIControlState state) { @@ -66,11 +70,11 @@ static inline NSNumber * backgroundImageURLKeyForState(UIControlState state) {
66 options:(SDWebImageOptions)options 70 options:(SDWebImageOptions)options
67 completed:(nullable SDExternalCompletionBlock)completedBlock { 71 completed:(nullable SDExternalCompletionBlock)completedBlock {
68 if (!url) { 72 if (!url) {
69 - [self.imageURLStorage removeObjectForKey:@(state)]; 73 + [self.imageURLStorage removeObjectForKey:imageURLKeyForState(state)];
70 return; 74 return;
71 } 75 }
72 76
73 - self.imageURLStorage[@(state)] = url; 77 + self.imageURLStorage[imageURLKeyForState(state)] = url;
74 78
75 __weak typeof(self)weakSelf = self; 79 __weak typeof(self)weakSelf = self;
76 [self sd_internalSetImageWithURL:url 80 [self sd_internalSetImageWithURL:url