Reputation: 2535
Hi Im trying to download a Photo from the internet using GCD. After the image is downloaded I call the delegate to let the class know that the image is downloaded.
Here is the code I use to download the image
-(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);
}
Here is how I implemented my Protocol in my POIPhoto.h
@protocol POIPhotoProtocol <NSObject>
-(void)gotVenuePhotos:(UIImage *)image;
@end
@interface POIPhoto : NSObject
-(void)getVenuePhotos:(NSString *)venueID;
@property(nonatomic, weak) id <POIPhotoProtocol> delegate;
@end
And in my class I want the call back
@interface PoiDetailViewController : UIViewController <POIPhotoProtocol>
And finaly I implement the protocol method
-(void)gotVenuePhotos:(UIImage *)image
{
self.venuePhoto.image = image;
}
The problem is that the gotVenuePhotos
never gets called even though in my image downloader the [self.delegate gotVenuePhotos:image];
gets called
Upvotes: 0
Views: 136
Reputation: 107231
The issue is happening because you are not setting the delegate.
In your viewDidLoad
set the delegate like:
self.delegate = self;
Upvotes: 2