ios - MKAnnotationView show different text on label -


i want display different text on each annotationview, same value displayed on every annotation.

following code :

    nsmutablearray *strannotitle;     -(void)calladdannotations{     cnt = 0;     [_mapview removeannotations:[_mapview annotations]];     (id obj in arrproptemp) {          cllocationcoordinate2d coords = cllocationcoordinate2dmake([[[arrproptemp valueforkey:@"latitude"] objectatindex:cnt] floatvalue], [[[arrproptemp valueforkey:@"longitude"] objectatindex:cnt] floatvalue]);          strannotitle[cnt] = [obj valueforkey:@"listpriceformap"];          // add annotation         mkpointannotation *point = [[mkpointannotation alloc] init];         point.coordinate = coords;         [self.mapview addannotation:point];          cnt++;       } }       -(mkannotationview *)createannotation:(mkannotationview *)viewan{     uilabel *lbl = (uilabel *)[viewan viewwithtag:100];     [lbl settext:strannotitle[cnt]];     return viewan; }  - (mkannotationview *)mapview:(mkmapview *)mapview viewforannotation:(id<mkannotation>)annotation {     if ([annotation iskindofclass:[mkuserlocation class]])         return nil;      mkannotationview *viewan = [[[nsbundle mainbundle] loadnibnamed:@"mapannotation" owner:self options:nil] lastobject];          viewan = [self createannotation:viewan];      return viewan;     return nil; } 

output:

enter image description here

where getting wrong? how solve this?

change implementation .

-(void)calladdannotations{     cnt = 0;     [_mapview removeannotations:[_mapview annotations]];     (id obj in arrproptemp) {          cllocationcoordinate2d coords = cllocationcoordinate2dmake([[[arrproptemp valueforkey:@"latitude"] objectatindex:cnt] floatvalue], [[[arrproptemp valueforkey:@"longitude"] objectatindex:cnt] floatvalue]);          strannotitle[cnt] = [obj valueforkey:@"listpriceformap"];          // add annotation         mkpointannotation *point = [[mkpointannotation alloc] init];         point.coordinate = coords;         [point settitle:strannotitle[cnt]];         [self.mapview addannotation:point];          cnt++;       } } 

change create method

-(mkannotationview *)createannotation:(mkannotationview *)viewan{     uilabel *lbl = (uilabel *)[viewan viewwithtag:100];     [lbl settext: viewan.annotation.title];//can move delegate     return viewan; } 

change viewforannotation method this.

-(mkannotationview *)mapview:(mkmapview *)mapview viewforannotation:(id<mkannotation>)annotation{ static nsstring *cabannotationidentifier=@"cabannotationidentifier"; mkannotationview * viewan =[mapview dequeuereusableannotationviewwithidentifier:cabannotationidentifier]; if(!annotationview){                 mkannotationview *viewan = [[[nsbundle mainbundle] loadnibnamed:@"mapannotation" owner:self options:nil] lastobject];      viewan = [self createannotation:viewan]; } return viewan; 

}


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -