ios - Loading online data very slow difficult to PUSH -


first of running map page show pins on map every store. running 1 pin on map , fast after put more 25 pins push slow map page. doing @ process app load data of pin location (as see in target output) , push next screen. please problem?

- (void)viewdidload {  [super viewdidload];  self.title = @"";  self.navigationitem.title = @"mek";  response = [[nsdata alloc] initwithcontentsofurl:[nsurl urlwithstring:@"http://kalkatawi.com/maplocation.php"]];  if(response!=nil) {      nserror *parseerror = nil;      jsonarray = [nsjsonserialization jsonobjectwithdata:response options:nsjsonreadingallowfragments error:&parseerror];      jsonarray1 = [[nsmutablearray alloc] init];     jsonarray2 = [[nsmutablearray alloc] init];     jsonarray3 = [[nsmutablearray alloc] init];      for(int i=0;i<[jsonarray count];i++)     {         name = [[jsonarray objectatindex:i] objectforkey:@"name"];          longitude = [[jsonarray objectatindex:i] objectforkey:@"longitude"];          latitude = [[jsonarray objectatindex:i] objectforkey:@"latitude"];           [jsonarray1 addobject:name];          [jsonarray2 addobject:longitude];          [jsonarray3 addobject:latitude];           self.locationmap.delegate = self;  //set delegate before adding annotations          cllocationcoordinate2d annotationcoord;          (int i=0; < [jsonarray count]; i++)         {             nsdictionary *annotationdictionary = [jsonarray objectatindex:i];              name = [annotationdictionary objectforkey:@"name"];              annotationcoord.latitude             = [[annotationdictionary objectforkey:@"longitude"] doublevalue];             annotationcoord.longitude             = [[annotationdictionary objectforkey:@"latitude"] doublevalue];              mkpointannotation *annotationpoint = [[mkpointannotation alloc] init];             annotationpoint.coordinate = annotationcoord;             annotationpoint.title = name;             annotationpoint.subtitle = [nsstring stringwithformat:@"%f %f", annotationpoint.coordinate.latitude, annotationpoint.coordinate.longitude];               [self.locationmap addannotation:annotationpoint];              //------------------------//              mkcoordinateregion region = mkcoordinateregionmakewithdistance(annotationpoint.coordinate, 50000, 50000);             [self.locationmap setregion:[self.locationmap regionthatfits:region] animated:yes];              locationmanager = [[cllocationmanager alloc] init];             locationmanager.distancefilter = kcldistancefilternone;             locationmanager.desiredaccuracy = kcllocationaccuracyhundredmeters;             [locationmanager startupdatinglocation];              lat = locationmanager.location.coordinate.latitude;             lon = locationmanager.location.coordinate.longitude;         }       }  }  else {      uialertview *alert=[[uialertview alloc]initwithtitle:@"you not connected internet" message:@"please check internet connection" delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil];     [alert show]; } } 

- (mkannotationview *)mapview:(mkmapview *)mv viewforannotation:(id <mkannotation>)annotation {  mkannotationview *pinview = nil;  if(annotation != locationmap.userlocation) {     static nsstring *defaultpinid = @"mypin";      pinview = (mkannotationview *)[locationmap dequeuereusableannotationviewwithidentifier:defaultpinid];     if ( pinview == nil )         pinview = [[[mkannotationview alloc] initwithannotation:annotation reuseidentifier:defaultpinid] autorelease];      pinview.image = [uiimage imagenamed:@"pinpinpin.png"];     pinview.canshowcallout = yes;     pinview.enabled = yes;      uibutton *infobutton = [uibutton buttonwithtype:uibuttontypedetaildisclosure];     pinview.rightcalloutaccessoryview = infobutton; }  return pinview; } 

simple way load data in background thread, , when data load display on map. can in of view controller, means can in parent view controller , when got response update on map view controller. or on view did load method load data in background , update when load. approach not hold ui. can use blocks this

dispatch_async(queue, ^{  //load data server      dispatch_async(dispatch_get_main_queue(), ^{          //update map     }); }); 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -