2011-09-08 5 views
0

plist에 저장된 이미지 경로 (예 : annotation1.jpg)를 가져와 POI에 따라 사용자 정의 설명 선을 넣으려고합니다. 지금 당장은 하나의 정적 이미지 만 가져옵니다.plist에서 이미지 경로 가져 오기

어떻게 구현할 수 있습니까?

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { 
     if (annotation == self.calloutAnnotation) { 
      CalloutMapAnnotationView *calloutMapAnnotationView = (CalloutMapAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:@"CalloutAnnotation"]; 
      if (!calloutMapAnnotationView) { 
       calloutMapAnnotationView = [[[CalloutMapAnnotationView alloc] initWithAnnotation:annotation 
                       reuseIdentifier:@"CalloutAnnotation"] autorelease]; 
       calloutMapAnnotationView.contentHeight = 78.0f; 
       UIImage *asynchronyLogo = [UIImage imageNamed:@"something.png"]; 
       UIImageView *asynchronyLogoView = [[[UIImageView alloc] initWithImage:asynchronyLogo] autorelease]; 
       asynchronyLogoView.frame = CGRectMake(5, 2, asynchronyLogoView.frame.size.width, asynchronyLogoView.frame.size.height); 
       [calloutMapAnnotationView.contentView addSubview:asynchronyLogoView]; 
      } 
      calloutMapAnnotationView.parentAnnotationView = self.selectedAnnotationView; 
      calloutMapAnnotationView.mapView = self.mapView; 
      return calloutMapAnnotationView; 
     } else if ([annotation isKindOfClass:[MyHomeAnnotation class]]) { 
      MKPinAnnotationView *annotationView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation 
                        reuseIdentifier:@"CustomAnnotation"] autorelease]; 
      annotationView.canShowCallout = NO; 
      annotationView.pinColor = MKPinAnnotationColorGreen; 
      return annotationView; 
     }else if ([annotation isKindOfClass:[MyMapAnnotation class]]) { 
      MKPinAnnotationView *annotationView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation 
                        reuseIdentifier:@"NormalAnnotation"] autorelease]; 
      annotationView.canShowCallout = NO; 
      annotationView.pinColor = MKPinAnnotationColorRed; 
      return annotationView; 
     } 


     return nil; 
    } 

감사합니다.

당신이있는 NSDictionary에 PLIST를로드 할 수 있습니다

답변

2

: 당신이 사전을 일단

NSDictionary *myDictionary = [NSMutableDictionary dictionaryWithContentsOfFile:pathAndFileName]; 

, 당신은 당신이 필요로하는 핵심 당겨 수 있습니다

NSString *imageFileName = [myDictionary objectForKey:@"imageFileName"]; 

을 그런 다음 이미지를 바로 만들 수 있습니다 (번들에 포함되어있는 한)

UIImage *image = [UIImage imageNamed:imageFileName]; 
+0

지금 내 코드는 다음과 같습니다. 'if (! calloutMapAnnotationView) { calloutMapAnnotationView = [[[CalloutMapAnnotationView alloc]] initWithAnnotation : annotation reuseIdentifier : @ "CalloutAnnotation"] autorelease]; calloutMapAnnotationView.contentHeight = 78.0f; NSDictionary * poiImage = [poiArray objectAtIndex : nextPoiIndex ++]; \t \t \t NSString * imageFileName = [poiImage objectForKey : @ "imageFileName"]; \t \t \t UIImage * asynchronyLogo = [UIImage imageNamed : @ "imageFileName"]; asynchronyLo' – danskcollignon

+0

하지만 Xcode는 imageFileName이 NSDictionary에 올바르게 통합되어 있어도 사용 된 변수가 아님을 알려줍니다. – danskcollignon

+0

디버거를 통해 이것을 실행하고 NSDictionary 행을 참조해야합니다. nonnil 객체 포인터를 생성합니다. 마찬가지로 imageFileName이 다음 행에서 nil이면 키가 PLIST에 존재하지 않는다는 것을 의미합니다. 이것은 키 이름의 오타 (대소 문자를 구분 함)이거나 poiArray가 처음에 제대로 작성되지 않았을 수 있습니다. 희망이 도움이됩니다. –