nsdictionary ivar에서 objectForKey :를 호출하려고하는데 EXC_BAD_ACCESS 오류가 발생합니다. nsdictionary는 JSON 프레임 워크를 사용하여 생성 된 다음 유지됩니다. 내가 처음 사용할 때 (같은 루프를 실행 한 직후) 완벽하게 작동하지만 나중에 액세스하려고하면 아무 것도 작동하지 않습니다.EXC_BAD_ACCESS를 일으키는 NSDictionary
if (resultsDic == nil) {
NSLog(@"results dic is nil.");
}
if ([resultsDic respondsToSelector:@selector(objectForKey:)]) {
NSLog(@"resultsDic should respond to objectForKey:");
}
사전이 전무 적이 없지만, 항상 respondsToSelector에 충돌 : 내가 잘못이 무엇인지 알아 내려고 시도하는이 코드를하고있는 중이 야. 어떤 아이디어?
또한 : 사전이 상호 작용 가져옵니다 이들은 위 이외의 다른 장소 : 일도 후
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[connection release];
//get the data in a usable form
NSString *jsonString = [[NSString alloc] initWithData:downloadedData encoding:NSUTF8StringEncoding];
resultsDic = [jsonString JSONValue];
[self processResults];
NSLog(@"Success. Received %d bytes of data",[downloadedData length]);
[downloadedData release];
[jsonString release];
}
- (void)processResults
{
NSArray *resultsArr = [resultsDic objectForKey:@"results"];
CLLocationCoordinate2D coordinate = [self coordinateFromResult:[resultsArr objectAtIndex:0]];
NSLog(@"lat: %f lng: %f", coordinate.latitude, coordinate.longitude);
}
- (void)dealloc {
[resultsDic release];
[super dealloc];
}
디버거를 사용하고'resultsDic'에 여전히 유효한 참조가 포함되어 있는지/여전히 사전인지 확인 했습니까? –
그것은 0 키/값 쌍이 있다고합니다. 그러나 어떻게 사라질 수 있었는가, 사전은 유지되어야한다고 생각합니까? – aks