ios - add disclosure button to annotation and open information in new view controller -
i have been reading few other posts on disclosure buttons in annotations have been unable find helpful. adding annotations map locations parse json. add disclosure button these annotations , when disclosure button pressed load json information specific location in next viewcontroller. here code far displays annotation each location. viewcontroller.m
#import "viewcontroller.h" #import "annotation.h" #import "city.h" @interface viewcontroller () @end #define getdatalurl @"http://www.club-hop.com/apptest.php" @implementation viewcontroller @synthesize mapview,jsonarray,citiesarray; - (void)viewdidload { [super viewdidload]; [self retrievedata]; city * cityobject; // load external page uiwebview nsmutablearray * locations= [[nsmutablearray alloc]init]; cllocationcoordinate2d location; annotation * myann; for(int u=0; u<citiesarray.count;u++){ cityobject=[citiesarray objectatindex:u]; myann=[[annotation alloc]init]; nsnumber *alat= cityobject.latitude; nsnumber *alon= cityobject.longitude; double lat = [alat doublevalue]; double lon = [alon doublevalue]; location.latitude= lat; location.longitude=lon; myann.coordinate = location; myann.title=cityobject.clubname; myann.subtitle=cityobject.cityname; [locations addobject:myann];} [self.mapview addannotations:locations]; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } //class methods -(void) retrievedata{ nsurl * url= [nsurl urlwithstring:getdatalurl]; nsdata * data= [nsdata datawithcontentsofurl:url]; jsonarray= [nsjsonserialization jsonobjectwithdata:data options:kniloptions error:nil]; //setup cities array citiesarray=[[nsmutablearray alloc]init]; for(int i=0; i<jsonarray.count;i++){ nsstring * cid= [[jsonarray objectatindex:i] objectforkey:@"id"]; nsstring * cname= [[jsonarray objectatindex:i] objectforkey:@"cityname"]; nsstring * ccountry= [[jsonarray objectatindex:i] objectforkey:@"citycountry"]; nsstring * cline= [[jsonarray objectatindex:i] objectforkey:@"clubline"]; nsstring * clname= [[jsonarray objectatindex:i] objectforkey:@"clubname"]; nsnumber * clatitude= [[jsonarray objectatindex:i] objectforkey:@"latitude"]; nsnumber * clongitude= [[jsonarray objectatindex:i] objectforkey:@"longitude"]; [citiesarray addobject:[[city alloc]initwithcityname:cname andcitycountry:ccountry andclubname:clname andclubline:cline andlatitude:clatitude andlongitude:clongitude andcityid:cid]]; } }
viewcontroller.h
#import <uikit/uikit.h> #import <mapkit/mapkit.h> @interface viewcontroller : uiviewcontroller <mkmapviewdelegate> @property (weak, nonatomic) iboutlet mkmapview *mapview; @property (nonatomic, strong) nsmutablearray * jsonarray; @property (nonatomic, strong) nsmutablearray * citiesarray; -(void) retrievedata; @end
annotation.m
#import "annotation.h" @implementation annotation @synthesize coordinate,title,subtitle; @end
annotation.h
#import <foundation/foundation.h> #import <mapkit/mapkit.h> @interface annotation : nsobject @property(nonatomic,assign) cllocationcoordinate2d coordinate; @property(nonatomic, copy) nsstring * title; @property(nonatomic, copy) nsstring * subtitle; @end
here links may helpfull mapcallout apple
dowanload source code , check bridge
Comments
Post a Comment