ios - How to call a mapview current location zoom in method from appdelegate correctly? -
i have tried using method, reason wont zoom in on current location. there doing wrong?
appdelegate.m
-(void)handlenetworkchange { self.reachability = [reachability reachabilityforinternetconnection]; [self.reachability startnotifier]; networkstatus remotehoststatus = [self.reachability currentreachabilitystatus]; mapviewcontroller *mapviewcontroller = [[mapviewcontroller alloc]init]; if(remotehoststatus == notreachable) { self.internetreachable = no; } else { self.internetreachable = yes; [mapviewcontroller userlocation]; } } mapviewcontroller.m
-(void)userlocation { mkcoordinateregion mapregion; mapregion.center.latitude = self.mapview.userlocation.coordinate.latitude; mapregion.center.longitude = self.mapview.userlocation.coordinate.longitude; mapregion.span.latitudedelta = 0.2; mapregion.span.longitudedelta = 0.2; [self.mapview setregion:mapregion animated:yes]; }
i use nsnotificationcenter. set listener waits post notification, once post norification received fire selector
here how (very simple actually)
this needs go in view controller present map, best in viewdidload
[[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(runthisfunctionwhenready:) name:@"testnotification" object:nil]; he zoom method should placed in same viewcontroller - so:
-(void)runthisfunctionwhenready { // zoom map , other funky stuff } now, anywhere in app (delegate included) can fire posting notification this:
[[nsnotificationcenter defaultcenter] postnotificationname:@"testnotification" object:self];
Comments
Post a Comment