我正在使用XCode 4.5.1構建iOS 6應用程序爲什麼我的委託爲空?
我試圖使用我的控制器可用於檢索圖像的協議。然而,我的委託從來不叫我,儘管調用它是這樣的:
UIImage *image = [self.delegate mapViewController:self imageForAnnotation:aView.annotation];
當調試這條線,我可以看到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
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
你在哪裏設置委託? – Etan 2013-03-09 22:52:44
我看不到委託任務。 – CodaFi 2013-03-09 22:52:45
你確實不設置委託。順便說一句,你可以離開'@synthesize委託= _delegate;'自Xcode 4.4以來。編譯器會處理它 – s1m0n 2013-03-09 22:57:41