我正在使用 XCode 4.5.1 构建一个 iOS 6 应用程序
我正在尝试使用我的控制器可以用来检索图像的协议。但是,尽管我这样称呼它,但我的代表从未被调用过:
UIImage *image = [self.delegate mapViewController:self imageForAnnotation:aView.annotation];
当我调试这条线时,我可以看到self.delegate
它为空,尽管我将 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
MapViewController.m:
@implementation MapViewController
@synthesize delegate = _delegate;
我使用 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