2017-12-08 5 views
0

Ich benutze diesen Code für EndcodeURLString.Bilder Konnte nicht geladen werden

url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] 

Vor Stichwort ist die Verwendung für ohne stringByAddingPercentEscapesUsingEncoding,
und nach Schlüsselwort ist nach stringByAddingPercentEscapesUsingEncoding verwenden.

Es fügt 52 zu URL 2 (nicht funktioniert), aber in URL 1 ist (es funktioniert)

URL 1. vor =>
https://images-na.ssl-images-amazon.com/images/I/41e3n4R8cUL._SL160_.jpg

URL 1. Nach =>
https://images-na.ssl-images-amazon.com/images/I/41e3n4R8cUL._SL160_.jpg

URL 2. vor =>
https://images-na.ssl-images-amazon.com/images/I/41T%2BHZfQPsL._SL160_.jpg

URL 2. Nach =>
https://images-na.ssl-images-amazon.com/images/I/41T%252BHZfQPsL._SL160_.jpg

Sie in der zweiten URL sehen können, nach %2, hat es %252. Ich habe keine Ahnung, warum das passiert oder was die Lösung dafür ist.

Bellow Code Verwendung in cellForItemAtIndexPath

[Common loadPostImg:a_cell.imgProduct :[dictImage valueForKey:@"url"]]; 

+(void)loadPostImg :(UIImageView *)imgView :(NSString *)strUrl{ 
if (strUrl) 
{ 
    if (strUrl.length !=0) 
    { 
     strUrl = [Common appendURL:strUrl]; 

     [imgView setShowActivityIndicatorView:NO]; 
     imgView.backgroundColor = [UIColor clearColor]; 
     NSLog(@"before => %@",strUrl); 
     strUrl = [Common endcodeURLString:strUrl]; 
     NSLog(@"After => %@",strUrl); 
     [imgView sd_setImageWithURL:[NSURL URLWithString:strUrl] placeholderImage:[UIImage imageNamed:@"DefaultBanner"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) 
     { 
      [imgView stopAnimating]; 
     }]; 

    } 
    else 
    { 
     imgView.image = [UIImage imageNamed:@"DefaultBanner"]; 
    } 
} 
else 
{ 
    imgView.image = [UIImage imageNamed:@"DefaultBanner"]; 
}} 

+(NSString *)endcodeURLString :(NSString *)url{ 
url = [url stringByReplacingOccurrencesOfString:@"%20" withString:@" "]; 
url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
return url;} 

Antwort

0

Sie mögen dieses

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 100, 100)]; 
imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:<Your original URL without percentage escaping>]]]; 
[self.view addSubview:imageView]; 

Hoffnung tun kann dies hilft