协议委托不会被调用

时间:2012-11-06 05:08:48

标签: objective-c ios

您好我试图使用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];被调用

1 个答案:

答案 0 :(得分:2)

问题正在发生,因为您没有设置委托。 在viewDidLoad中设置委托代码:

self.delegate = self;