嗨,我正在尝试使用 GCD 从互联网下载照片。下载图像后,我打电话给代表,让班级知道图像已下载。
这是我用来下载图像的代码
-(void)getVenuePhotos:(NSString *)venueID
{
dispatch_queue_t getVenuePhotos = dispatch_queue_create ( "getVenuePhotos" , NULL );
dispatch_async (getVenuePhotos, ^{
//Download image, Lots of code not displaying
UIImage *image = [[UIImage alloc] initWithData:photoData];
dispatch_async(dispatch_get_main_queue(),^{
//This delegate doesn't get called
[self.delegate gotVenuePhotos:image];
});
});
dispatch_release (getVenuePhotos);
}
这是我在 POIPhoto.h 中实现协议的方式
@protocol POIPhotoProtocol <NSObject>
-(void)gotVenuePhotos:(UIImage *)image;
@end
@interface POIPhoto : NSObject
-(void)getVenuePhotos:(NSString *)venueID;
@property(nonatomic, weak) id <POIPhotoProtocol> delegate;
@end
在我的课堂上,我想要回电
@interface PoiDetailViewController : UIViewController <POIPhotoProtocol>
最后我实现了协议方法
-(void)gotVenuePhotos:(UIImage *)image
{
self.venuePhoto.image = image;
}
问题是gotVenuePhotos
永远不会被调用,即使在我的图像下载器中[self.delegate gotVenuePhotos:image];
被调用