Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my delegate null? [closed]

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
like image 243
seedhead Avatar asked Apr 13 '26 17:04

seedhead


1 Answers

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.

like image 192
matt Avatar answered Apr 15 '26 09:04

matt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!