2010-05-06 3 views
0

죄송합니다.이 질문은 멍청한 질문 일 수 있습니다. 그러나 CoreLocation과 관련하여이 문제가 해결되지 않았습니다.CLLocation이 0이 아니지만 인쇄하려고 시도합니다. EXC_BAD_ACCESS

이 사이트에서 권장하는 싱글 톤을 사용하여 currentLocation을 찾고 있는데 currentLocation 객체를 얻으면 nil이 아닌 검사에 true를 반환합니다. 그러나 설명을 인쇄하려고하면 EXC_BAD_ACCESS가 throw됩니다.

//WORKS Current location 8.6602e-290 
NSLog(@"Current location %g",currLoc); 

//DOESN'T WORK 
NSLog(@"Current location %@",[currLoc description]); 

//DOESN'T WORK - Is this causing the description to fail as well? 
NSLog(@"Current location %g",currLoc.coordinate.latitude); 

왜 처음에는 아무것도 볼 수 있습니까? BTW,이 3.1.2 시뮬레이터에서 실행되고 있습니다. 감사. %의 g는

NSLog(@"Current location %f",currLoc.coordinate.latitude); 
+0

혹시 이것을 해결 했습니까? 속성 위도 또는 경도에 액세스 할 때마다 이것도보고 있습니다 ... – scham

답변

1

currLoc.coordinate.latitude 당신은 % f를 사용할 수 있습니다 ... 두 번 입력합니다. 그러나 해제 된 개체 (댕글 포인터) 가능성이있을 수 있습니다. 이것은 nil 검사 조건을 통과합니다. 이것은 당신 문제 일 수 있습니다.

currLoc 멤버를 직접 사용하는 대신 currLoc 용 액세서를 사용하십시오. 이 문제가 해결됩니다 :)

+0

또한 EXC_BAD_ACCESS가 throw됩니다. – Nefsu

0

currLoc이을 확인 NIL하지 TRUE에 대한 반환 될 수 있습니다 작동하지 않는 경우

+0

죄송합니다, 아마도 명확하지 않았습니다. currLoc은 실제로이 컨트롤러에서 설정하는 로컬 변수이지만 locationController.currentLocation으로 설정됩니다. LocationController는 CLLocationManagerDelegate를 구현하는 인터페이스입니다. – Nefsu

0
// malformed: %g format specifier expects type 
// double, you're passing an objc object. 
// sending arguments through (...) with the 
// invalid types/widths is a near certain way 
// to crash an app, and the data will be useless 
// to the function called (NSLog in this case) 
NSLog(@"Current location %g",currLoc); 

// try running the app with zombies enabled. 
// in short, enabling zombies (NSZombiesEnabled) 
// is a debugging facility to determine whether 
// you use an objc object which would have been freed. 
NSLog(@"Current location %@",[currLoc description]); 

// as long as currLoc is a pointer to a valid (non-freed) 
// objc object, then this should be fine. if it is not valid 
NSLog(@"Current location %g",currLoc.coordinate.latitude); 
+0

내 질문에 currLog 수없는 상황을 통과하고 currLoc.coordinate.latitude 액세스하려는 동안 여전히 오류가 던질 수있는 것 같아요. currLoc을 점검하여 LocationManager에서 값을 설정했는지 확인하고 해당 변수의 설정을 추적하는 BOOL var을 추가하여 문제를 해결할 수있었습니다. 의견을 보내 주셔서 감사합니다. 추신. 나는 보통 테스트를하는 동안 NSZombie를 사용할 수있게했으며 디버깅하는 동안 도움이되는 것을 보지 못했습니다. 티 – Nefsu