나는 질문의 위치/종류에 따라 다른 핀 색상을 나타내는지도를 설정하려고합니다. 이것은 꽤 일반적인 일이지만, viewForAnnotation 델리게이트가 핀 색상을 일관되게 업데이트/설정하도록하는 데 어려움을 겪고 있습니다.
는 내가 설정 기본적으로 사이클 AddressAnnotations의 목록을 다음은 주석 클래스 (버스 정류장, 병원 등)에 따라 showThisLocation 기능이iPhone MapKit 문제 : viewForAnnotation이 일관되게 pinColor를 설정하지 않습니까?
if(myClass == 1){
[defaults setObject:@"1" forKey:@"currPinColor"];
[defaults synchronize];
NSLog(@"Should be %@!", [defaults objectForKey:@"currPinColor"]);
} else if(myClass ==2){
[defaults setObject:@"2" forKey:@"currPinColor"];
[defaults synchronize];
NSLog(@"Should be %@!", [defaults objectForKey:@"currPinColor"]);
}
[_mapView addAnnotation:myCurrentAnnotation];
다음 내 viewForAnnotation 위양이,
이처럼 보이는
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
if(annotation == mapView.userLocation){ return nil; }
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
MKPinAnnotationView *annView = nil;
annView = (MKPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@"currentloc"];
if(annView == nil){
annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
}
annView.pinColor = [defaults integerForKey:@"currPinColor"];
NSLog(@"Pin color: %d", [defaults integerForKey:@"currPinColor"]);
annView.animatesDrop=TRUE;
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);
return annView;
}
"if"블록의 NSLog 문은 항상 색이 설정되었음을 확인하지만 대리자는 경우에 따라 항상 올바른 색으로 끝나는 것은 아닙니다. 또한 일반적으로 새로운 위치를 검색하면 "if"블록의 마지막 색상으로 모든 핀이 설정되지만 동일한 위치를 다시 검색하면 핀이 올바른 색상으로 설정됩니다.
나는이 방법으로 NSUserDefaults를 사용하지 않을 것으로 생각하지만, "currentPinColor"라는 추가 속성을 포함하는 MKAnnotation에 대한 내 자신의 하위 클래스를 만들려고했는데,이 동안 "currentPinColor"를 설정할 수있었습니다. 나는 delegate 메소드에서 "currentPinColor"에 접근하려고 시도했다. 컴파일러는 MKAnnotation과 관련하여 "currentPinColor"에 대해 아무것도 모른다고 불평했다. 공정한 충분히 내가 대리자 방법을 수정하려고 다음 생각, 대신 기본의
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MyCustomMKAnnotation>)annotation
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
하는 컴파일러가 그것을위한 프로토콜에 대해 아무것도 몰랐다 불평 포인트 이 위임 컨텍스트의 MyCustomMKAnnotation입니다.
위임 메서드 및/또는 MyCustomMKAnnotation을 설정하는 올바른 방법은 무엇입니까? 일관된 핀 색상 설정을 얻는 데 적합한 방법은 무엇입니까? 나는 사물에 대한 아이디어를 여기에서 시도하는 것에 관한 것입니다.
왜 내 질문에 답변하는 데 2 일이 걸립니까? – si28719e
3 번 줄에있는 'AddressAnnotation'은 무엇입니까? –