iOS: Dynamic Marker Info Window

我的梦境 提交于 2019-12-10 16:54:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!