iphone - getting the details to show above an annotation -
iphone - getting the details to show above an annotation -
ok have annotations showing fine can't figure out how little dialogue box thing appear above it. when create annotation, this:
annotation *annot = [[annotation alloc] init]; annot.coordinate = touchmapcoordinate; annot.title = @"location"; annot.subtitle = @"the address"; [self.mapview addannotation:annot];
again, works find doesn't show little dialogue box.
i understand has delegate. downloaded apple's mapcallouts illustration code , couldn't figure out how contacted delegate annotations.
here annotations class
annotation.h
#import <foundation/foundation.h> #import <mapkit/mapkit.h> @interface annotation : nsobject <mkannotation>{ cllocationcoordinate2d coordinate; nsstring *title; nsstring *subtitle; } @property (nonatomic) cllocationcoordinate2d coordinate; @property (nonatomic, copy) nsstring *title; @property (nonatomic, copy) nsstring *subtitle; -(id)initwithcoordinate:(cllocationcoordinate2d) c title:(nsstring *) t subtitle:(nsstring *) st; -(void) moveannotation: (cllocationcoordinate2d) newcoordinate; -(nsstring *)subtitle; -(nsstring *)title; @end
annotation.m
#import "annotation.h" @implementation annotation @synthesize coordinate = _coordinate; @synthesize title = _title; @synthesize subtitle = _subtitle; -(id)initwithcoordinate:(cllocationcoordinate2d)c title:(nsstring *)t subtitle:(nsstring *)st { coordinate = c; self.title = t; self.subtitle = st; homecoming self; } -(void)moveannotation:(cllocationcoordinate2d)newcoordinate { coordinate = newcoordinate; } -(nsstring *)subtitle { homecoming subtitle; } -(nsstring *)title{ homecoming title; } @end
here delagate set up:
-(mkannotationview *)mapview:(mkmapview *)amapview viewforannotation:(id < mkannotation >)annotation { if ([annotation iskindofclass:[annotation class]]) { static nsstring *reuseid = @"customann"; mkannotationview *customannotationview = [amapview dequeuereusableannotationviewwithidentifier:reuseid]; if (customannotationview == nil) { customannotationview = [[mkannotationview alloc] initwithannotation:annotation reuseidentifier:reuseid]; uiimage *pinimage = [uiimage imagenamed:@"pin-green.png"]; [customannotationview setimage:pinimage]; customannotationview.canshowcallout = yes; uibutton *rightbutton = [uibutton buttonwithtype:uibuttontypedetaildisclosure]; customannotationview.rightcalloutaccessoryview = rightbutton; } customannotationview.annotation = annotation; homecoming customannotationview; } homecoming nil; }
if need more info me, allow me know , give thanks in advance!
you need implement next mkmapviewdelegate method on mkmapview's delegate:
- (mkannotationview *)mapview:(mkmapview *)mapview viewforannotation:(id < mkannotation >)annotation
make sure homecoming mkannotationview canshowcallout
enabled.
iphone ios ios5 mapkit
Comments
Post a Comment