ios - Some methods in class do not recognize that instance of MKMapView already exists -
i trying turn on user tracking mode mkmapview. mkmapview part of storyboard, believe automatically initialized. when run debugger on viewdidload
, viewdidappear
, prints address of mkmapview, seems initialized. here methods in firstviewcontroller class:
#import "firstviewcontroller.h" #import "options.h" #import "appdelegate.h" @interface firstviewcontroller () @end @implementation firstviewcontroller - (void)viewdidload { [super viewdidload]; // additional setup after loading view, typically nib. appdelegate *appdelegate = (appdelegate *)[[uiapplication sharedapplication] delegate]; self.currentmap.delegate = self; [appdelegate.locationmanager requestalwaysauthorization]; appdelegate.locationmanager.distancefilter = 20.0; } - (void)viewdidappear:(bool)animated { [super viewdidappear:no]; if ([cllocationmanager authorizationstatus] != kclauthorizationstatusauthorizedalways) { uialertview *alert= [[uialertview alloc]initwithtitle:@"cannot access location" message:@"please allow location services in settings." delegate:nil cancelbuttontitle:@"ok" otherbuttontitles: nil]; [alert show]; } self.currentmap.showsuserlocation = [[nsuserdefaults standarduserdefaults] boolforkey:@"maplocation"]; } - (void)changetracking { if (self.currentmap.usertrackingmode == mkusertrackingmodenone) { [self.currentmap setusertrackingmode:mkusertrackingmodefollow animated:yes]; } else if (self.currentmap.usertrackingmode == mkusertrackingmodefollow) { [self.currentmap setusertrackingmode:mkusertrackingmodenone animated:yes]; } }
when call [appdelegate.firstviewcontroller changetracking]
class, changetracking
method executes, thinks self.currentmap
nil
. when changes user tracking mode, doesn't have effect on map recognized viewdidload
, viewdidappear
. why first 2 methods recognize instance of mkmapview changetracking
not?
you need better handle 1 what's going on.
do have outlet connected map view?
add nslog viewdidload method , log self.currentmap. log address of self.
then, in other methods, log address of self (using %x format string, , casting self unsigned long).
my guess: either outlet link broken or creating multiple instances of class without realizing it.
Comments
Post a Comment