XCode4.5.1を使用してiOS6アプリを構築しています
コントローラが画像を取得するために使用できるプロトコルを使用しようとしています。ただし、次のように呼び出しているにもかかわらず、代理人が呼び出されることはありません。
UIImage *image = [self.delegate mapViewController:self imageForAnnotation:aView.annotation];
この行をデバッグするself.delegate
と、TableViewControllerをそのデリゲートに関連付けているにもかかわらず、nullであることがわかります。
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