모든 내 위치, 제목 및 자막이 포함 된 NSSDictionary를 가져 와서이를 통해 열거하고이를 mapView에 추가하십시오. 첫 번째 부분은 괜찮아 보입니다. 나는 Plist를 읽고 다양한 부분에 액세스 할 수 있습니다. 문제가있는 것은 열거를 통해 실행 중입니다.iOS MapKit 배우기 - NSDictionary의지도에있는 다중 핀
제목을 묻는 NSLog는 해당 속성을 콘솔에 올바르게보고합니다.
결국에는 핀이 보이지 않습니다. 또한, NSLog 호출 후 :
NSLog(@"My %i annotations are: %@", self.mapView.annotations.count, self.mapView.annotations);
나는 응답 얻을 : 표시
"My 1 annotations are: (
"<MKPointAnnotation: 0xd0151f0>")
는 한 주석만을위한 한 메모리 위치로. Sigh.
나는 간단하고 잘못한 것을하고 있지만 어떤 도움을 주겠다고 확신합니다. 나는 하루 종일 수색 해 왔으며 여기에 답으로 보이는 것들을 보았지만이 특별한 건축에서 나를 돕는 어떤 것도 보지 못했습니다.
미리 감사드립니다.
다음 코드는 주 viewController에서 시작됩니다. 첫 번째 메서드는 ViewDidLoad의 끝에서 호출됩니다.
-(void) loadUpLocations{
NSPropertyListFormat format;
NSString *errorDesc=nil;
//make path to plist in bundle
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"locations2" ofType:@"plist"];
//fill data object with contents of file
NSData *myData = [[NSData alloc] initWithContentsOfFile:plistPath];
myLocations=[NSPropertyListSerialization propertyListFromData:myData
mutabilityOption:NSPropertyListMutableContainersAndLeaves
format:&format
errorDescription:&errorDesc];
if (!myLocations) {
NSLog(@"Error reading Plist: %@ format: %@", errorDesc,format);
}
myAnnotation=[[MKPointAnnotation alloc]init];
for (NSString *loc in myLocations) {
NSDictionary *value =[myLocations objectForKey:loc];
//NSLog(@"Loc is equal to: %@",loc);
//loop through and make annotations
myAnnotation.coordinate = CLLocationCoordinate2DMake(
[[value objectForKey:@"latitude"] doubleValue],
[[value objectForKey:@"longitude"] doubleValue]);
myAnnotation.title = [value objectForKey:@"title"];
myAnnotation.subtitle = [value objectForKey:@"subtitle"];
NSLog(@"%@",myAnnotation.title);
[self.mapView addAnnotation:myAnnotation];
}
NSLog(@"My %i annotations are: %@", self.mapView.annotations.count, self.mapView.annotations);
}
- (IBAction)zoomToLocation:(id)sender {
//set center for zoom
MKCoordinateRegion region;
region.center=CLLocationCoordinate2DMake(33.75070416856952, -84.37034368515015);;
//set level of zoom
MKCoordinateSpan span;
span.latitudeDelta=.03;
span.longitudeDelta=.03;
region.span=span;
[mapView setRegion:region animated:YES];
}
// This gets called every time an annotation is in the map view
- (MKAnnotationView *)mapView:mapView viewForAnnotation:annotation{
NSLog(@"in annotationsView");
MKPinAnnotationView *myPins=[[MKPinAnnotationView alloc]
initWithAnnotation:annotation
reuseIdentifier:@"myPins"];
myPins.animatesDrop=YES;
return myPins;
}
그래, ARC를 사용하고 있습니다. 루프를 초기화 할 때 오류가 계속 발생했습니다. 그것은 조기에 공개되는 인스턴스에 대해 불평했다. 다시 시도하고 실제 오류와 함께보고합니다. 감사합니다. –
다음은 오류입니다. MKPointAnnotation 클래스의 인스턴스 0x6d2f2f0은 키 값 옵저버가 등록되어있는 동안 할당이 해제되었습니다. 관측 정보가 누출되어 다른 물체에 실수로 부착 될 수 있습니다. NSKVODeallocateBreak에 중단 점을 설정하여 디버거에서 여기서 중단합니다. 현재 관찰 정보는 다음과 같습니다 : ( 컨텍스트 : 0x0, 속성 : 0x6d2d5e0> –
그 오류는 위도 또는 경도 값이 유효하지 않은 경우에 발생할 수 있습니다. myAnnotation.coordinate를 설정 한 후 'NSLog (@ "lat = % f, long = % f", myAnnotation.coordinate.latitude, myAnnotation 위도가 -90에서 90 사이이고 경도가 -180에서 180 사이인지 확인하십시오. – Anna