I am building an iOS 6 app using XCode 4.5.1
I am trying to use a protocol which my controller can use to retrieve an image. However, my delegate is never called despite me calling it like this:
UIImage *image = [self.delegate mapViewController:self imageForAnnotation:aView.annotation];
When I debug this line I can see self.delegate is null, despite me associating a TableViewController to be its delegate.
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;
I am using a TableViewController as the 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
None of your code shows you setting anything as the delegate of anything else. You declare some properties and you adopt some protocols but none of that actually sets the delegate property of self to a value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With