为什么我的代表为空?

see*_*ead 3 protocols objective-c ios

我正在使用XCode 4.5.1构建iOS 6应用程序

我正在尝试使用我的控制器可以用来检索图像的协议.但是,尽管我这样称呼我的代表,但我的代表从未被调用:

UIImage *image = [self.delegate mapViewController:self imageForAnnotation:aView.annotation];
Run Code Online (Sandbox Code Playgroud)

当我调试此行时,我可以看到self.delegate为null,尽管我将TableViewController关联为其委托.

MapViewController.h:

@class MapViewController;
@protocol MapViewControllerDelegate <NSObject>
    - (UIImage *)mapViewController:(MapViewController *)sender imageForAnnotation:(id <MKAnnotation>)annotation;
@end

@interface MapViewController : UIViewController
@property (nonatomic, weak) id <MapViewControllerDelegate> delegate;
@end
Run Code Online (Sandbox Code Playgroud)

MapViewController.m:

@implementation MapViewController
@synthesize delegate = _delegate;
Run Code Online (Sandbox Code Playgroud)

我使用TableViewController作为MapViewControllerDelegate:

@interface RecentPhotosTableViewController () <MapViewControllerDelegate>

- (PhotoViewController *) splitViewPhotoViewController;
@end

@implementation RecentPhotosTableViewController
- (UIImage *)mapViewController:(MapViewController *)sender imageForAnnotation:(id <MKAnnotation>)annotation
{
    FlickrPhotoAnnotation *fpa = (FlickrPhotoAnnotation *)annotation;
    NSURL *url = [FlickrFetcher urlForPhoto:fpa.photo format:FlickrPhotoFormatSquare];
    NSData *data = [NSData dataWithContentsOfURL:url];
    return data ? [UIImage imageWithData:data] : nil;
}

@end
Run Code Online (Sandbox Code Playgroud)

mat*_*att 5

您的代码都没有显示您将任何内容设置为其他内容的代理.您声明了一些属性并采用了一些协议,但实际上并没有将delegate属性设置self为值.