iphone - 'MyAnnotation' may not respond to 'initWithDictionary:' -
i keep getting semantic issue code ('myannotation' may not respond 'initwithdictionary:'), im adding annotations map using plist.
even though displays pin , want to, semantic issue , cant seem solve problem
if great thanks
heres code, problem in //brewmapviewcontroller.m error on line
myannotation *annotation = [[myannotation alloc] initwithdictionary:brewerydict];
/*myannotation.h*/ #import <foundation/foundation.h> #import <mapkit/mapkit.h> @interface myannotation : nsobject <mkannotation> { cllocationcoordinate2d coordinate; nsstring *title; nsstring *subtitle; nsstring *test; } @property (nonatomic, readonly) cllocationcoordinate2d coordinate; @property (nonatomic, copy) nsstring *title; @property (nonatomic, copy) nsstring *subtitle; @property (nonatomic, copy) nsstring *test; @end
/*myannotation.m*/ #import "myannotation.h" @implementation myannotation @synthesize coordinate, title, subtitle, test; - (id) initwithdictionary:(nsdictionary *) dict { self = [super init]; if (self != nil) { coordinate.latitude = [[dict objectforkey:@"latitude"] doublevalue]; coordinate.longitude = [[dict objectforkey:@"longitude"] doublevalue]; self.title = [dict objectforkey:@"name"]; self.subtitle = [dict objectforkey:@"address"]; self.test = [dict objectforkey:@"test"]; } return self; } @end
/*brewmapviewcontroller.h*/ #import <uikit/uikit.h> #import <mapkit/mapkit.h> @interface brewmapviewcontroller : uiviewcontroller <mkmapviewdelegate> { iboutlet mkmapview *map; nsarray *breweries; } @end
/*brewmapviewcontroller.m*/ #import "brewmapviewcontroller.h" #import "myannotation.h" @implementation brewmapviewcontroller // implement viewdidload additional setup after loading view, typically nib. - (void)viewdidload { [super viewdidload]; breweries = [[nsarray alloc] initwithcontentsoffile:[[nsbundle mainbundle] pathforresource:@"test" oftype:@"xml"]]; double minlat = [[breweries valueforkeypath:@"@min.latitude"] doublevalue]; double maxlat = [[breweries valueforkeypath:@"@max.latitude"] doublevalue]; double minlon = [[breweries valueforkeypath:@"@min.longitude"] doublevalue]; double maxlon = [[breweries valueforkeypath:@"@max.longitude"] doublevalue]; mkcoordinateregion region; region.center.latitude = (maxlat + minlat) / 2.0; region.center.longitude = (maxlon + minlon) / 2.0; region.span.latitudedelta = (maxlat - minlat) * 1.05; region.span.longitudedelta = (maxlon - minlon) * 1.05; map.region = region; (nsdictionary *brewerydict in breweries){ myannotation *annotation = [[myannotation alloc] initwithdictionary:brewerydict]; [map addannotation:annotation]; [annotation release]; } } - (mkannotationview *)mapview:(mkmapview *)mapview viewforannotation:(id <mkannotation>)annotation{ if (map.userlocation == annotation){ return nil; } nsstring *identifier = @"my_identifier"; mkannotationview *annotationview = [map dequeuereusableannotationviewwithidentifier:identifier]; if (annotationview == nil){ annotationview = [[[mkannotationview alloc] initwithannotation:annotation reuseidentifier:identifier] autorelease]; annotationview.image = [uiimage imagenamed:@"beer.png"]; annotationview.canshowcallout = yes; annotationview.rightcalloutaccessoryview = [uibutton buttonwithtype:uibuttontypedetaildisclosure]; annotationview.leftcalloutaccessoryview = [[[uiimageview alloc] initwithimage:[uiimage imagenamed:@"pretzel.png"]] autorelease]; } return annotationview; } - (void)mapview:(mkmapview *)mapview annotationview:(mkannotationview *)view calloutaccessorycontroltapped:(uicontrol *)control { nslog(@"i've been tapped"); } - (bool)shouldautorotatetointerfaceorientation:(uiinterfaceorientation)interfaceorientation { return yes; } - (void)dealloc { [breweries release]; [map release]; [super dealloc]; } @end
you have put method signature - (id) initwithdictionary:(nsdictionary *) dict
header file in order tell brewmapviewcontroller
method exists:
/*myannotation.h*/ #import <foundation/foundation.h> #import <mapkit/mapkit.h> @interface myannotation : nsobject <mkannotation> { cllocationcoordinate2d coordinate; nsstring *title; nsstring *subtitle; nsstring *test; } @property (nonatomic, readonly) cllocationcoordinate2d coordinate; @property (nonatomic, copy) nsstring *title; @property (nonatomic, copy) nsstring *subtitle; @property (nonatomic, copy) nsstring *test; - (id) initwithdictionary:(nsdictionary *) dict; @end
Comments
Post a Comment