0
나는 응용 프로그램이 실행될 때 사용자 위치를 얻고 위치 변수가 @ (null) 인 경우 위 whit if 문을 방지합니다. 내 FirstViewController.h에서 :변수가 @ (null) 인 것을 방지함으로써 충돌을 피할 수 있습니까?
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[super viewDidLoad];
// Do any additional setup after loading the view.
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
[locationManager startUpdatingLocation];
}
CLLocationManager *locationManager;
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
CLLocation *currentLocation = newLocation;
if (currentLocation != NULL) {
[(AppDelegate *)[[UIApplication sharedApplication] delegate] setLatitude:[NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude]];
[(AppDelegate *)[[UIApplication sharedApplication] delegate] setLongitude:[NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude]];
}
}
내 SecondViewController에서이 if 문으로
-(void) GettingGlobalVariables{
NSString *UsersCurrentLatitude = [(AppDelegate *)[[UIApplication sharedApplication] delegate] latitude];
NSString *UsersCurrentLongitude = [(AppDelegate *)[[UIApplication sharedApplication] delegate] longitude];
NSNumberFormatter * singsingsing = [[NSNumberFormatter alloc] init];
[singsingsing setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber * myNumberLatitude = [singsingsing numberFromString:UsersCurrentLatitude];
NSNumberFormatter * sheCameToMeOneMorning = [[NSNumberFormatter alloc] init];
[sheCameToMeOneMorning setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber * myNumberLongitude = [sheCameToMeOneMorning numberFromString:UsersCurrentLongitude];
NSLog(@"mynumberlatitude:%@,mynumberlongitude:%@",myNumberLongitude,myNumberLatitude);
if (!myNumberLatitude) {
NSLog(@"location variables are null");
TabBar *TB =[[TabBar alloc]init];
[TB performSelector:@selector(viewDidLoad)];
[TB performSelector:@selector(locationManager:didUpdateToLocation:fromLocation:)];
[self performSelector:@selector(GettingGlobalVariables)];
}
}
변수가 null 응용 프로그램 호감이다. 어떠한 제안? NSLog`만약 (! myNumberLatitude) { (@ "위치 변수가 null입니다"); :이 같은
충돌은 그 결과 if 문이다 TabBar * TB = [[TabBar alloc] init]; [TB performSelector : @selector (viewDidLoad)]; [TB performSelector : @selector (locationManager : didUpdateToLocation : fromLocation :)]; [self performSelector : @selector (GettingGlobalVariables)]; ' 그래서 if 문을 변경해야합니다. – ananana