问题
I'm trying to dynamically load an image into an infowindow. The issue is that SDWebImage doesn't ever complete. However, once I click the marker again the image shows and complete is called but never on the first time. My log for "run" shows on the first time so I know the code is being called but complete never shows on the first run unless the image is cached and in that case it will show on the second marker tap.
Side note: I'm storing the link to the image in snippet since I don't have another use for it.
Any ideas why SDWebImage doesn't complete? Or is there a better approach to this that anyone else can think of?
Last thing I see under blocks in documentation it says the following which seems to fit but I don't see how I'm canceling the request in anyway to cause this behavior.
Note: neither your success nor failure block will be call if your image request is canceled before completion.
bool tapped = NO;
-(BOOL) mapView:(GMSMapView *) mapVieW didTapMarker:(GMSMarker *)marker{
tapped=YES;
[mapVieW setSelectedMarker:marker];
return YES;
}
- (UIView *)mapView:(GMSMapView *)mapVieW markerInfoWindow:(GMSMarker *)marker{
if([marker.snippet isEqualToString:@""] || [marker.snippet isEqualToString:nil]){
//no image
tapped = NO;
//code here
return view;
}else{
//image
//code for custom view which is unimportant
if(tapped){
NSLog(@"run");
[image setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", URL_PREFIX, marker.snippet]] placeholderImage:[UIImage imageNamed:@"you"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
NSLog(@"complete");
tapped=NO;
[mapView setSelectedMarker:nil];
[mapView setSelectedMarker:marker];
}];
}
return view;
}
}
来源:https://stackoverflow.com/questions/23546764/ios-dynamic-marker-info-window