I tried to implement this:
UICRouteOverlayMapView
.h file
@protocol DrawingDataDelegate <NSObject>
@required
-(void) drawingSuccessful:(BOOL)done;
@end
@interface UICRouteOverlayMapView : UIView {
id <DrawingDataDelegate> delegate;
}
- (id)initWithMapView:(MKMapView *)mapView;
@property (nonatomic, retain) id <DrawingDataDelegate> delegate;
@end
.m file
@implementation UICRouteOverlayMapView
@synthesize delegate;
- (void)drawRect:(CGRect)rect {
NSLog(@"mesagge");
if ([self.delegate respondsToSelector:@selector(drawingSuccessful:)]) {
[self.delegate drawingSuccessful:YES];
}
}
The class that adopts the protocol:
.h file
#import "UICRouteOverlayMapView.h"
@class UICRouteOverlayMapView;
@interface ItineraireViewController : UIViewController <MKMapViewDelegate, UICGDirectionsDelegate, CLLocationManagerDelegate,
DrawingDataDelegate> {
UICRouteOverlayMapView *routeOverlayMapView;
}
.m file
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
routeOverlayMapView = [[UICRouteOverlayMapView alloc] init];
routeOverlayMapView.delegate = self;
}
-(void) drawingSuccessful:(BOOL)done{
NSLog(@"it's done");
}
Now, what am I doing wrong cause the method drawingSuccessful
never gets called?
I know for sure that the method
- (void)drawRect:(CGRect)rect {
NSLog(@"mesagge");
if ([self.delegate respondsToSelector:@selector(drawingSuccessful:)]) {
[self.delegate drawingSuccessful:YES];
}
}
is called because this gets displayed NSLog(@"mesagge");
.Please help
I did debug and set breakpoint at this line:
if ([self.delegate respondsToSelector:@selector(drawingSuccessful:)])
and I noticed that this is not a valid condition...it never enters the brackets...so this
it is not compiled [self.delegate drawingSuccessful:YES];
.
So, what is wrong?