0
我需要從web服務設置自定義圖像提取到這方面,我的方法中寫特定代碼的mapPins.For以一個特定註釋的數據到下一個視圖
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
NSLog(@"viewForAnnotation Method");
if([annotation isKindOfClass:[MKUserLocation class]])
return nil;
NSString *annotationIdentifier = @"CustomViewAnnotation";
MKAnnotationView* annotationView = [objMapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
if(!annotationView)
{
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:annotationIdentifier];
}
//annotationView.canShowCallout= YES;
NSLog(@"Annotation Index = %lu",(unsigned long)[mapView.annotations indexOfObject:annotation]);
Annotations *myCustomPinAnnot = (Annotations*)annotation;
NSLog(@"Selected title = %@",myCustomPinAnnot.title);
if ([myCustomPinAnnot.title isEqualToString:@" TOWER PLACE"]) {
arrayFromArray = [[NSMutableArray alloc] init];
NSString *eff0 = [[allDataArray objectAtIndex:0] pinEfficiencyObjectClass];
NSString *eff1 = [[allDataArray objectAtIndex:1] pinEfficiencyObjectClass];
NSString *eff2 = [[allDataArray objectAtIndex:2] pinEfficiencyObjectClass];
NSString *eff3 = [[allDataArray objectAtIndex:3] pinEfficiencyObjectClass];
[self calculateEfficiency:eff0 andSecondEff:eff1 andThirdEff:eff2 andFourthEff:eff3];
[arrayFromArray addObject:[allDataArray objectAtIndex:2]];
[arrayFromArray addObject:[allDataArray objectAtIndex:1]];
[arrayFromArray addObject:[allDataArray objectAtIndex:0]];
[arrayFromArray addObject:[allDataArray objectAtIndex:3]];
joinString=[NSString stringWithFormat:@"%@%@%@",@"mais_",[self getColourCode:eff0 andSecondEff:eff1 andThirdEff:eff2 andFourthEff:eff3],@".png"];
NSLog(@"Join String = %@",joinString); //JoinString is the image fetched from web service
UIImageView *imgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:joinString]];
[imgV setFrame:CGRectMake(0, 0, 40, 40)];
annotationView.image = imgV.image;
}
return annotationView;
}
我收到了4個引腳與相應的圖片。
現在,當我點擊一個特定的引腳,我可以將數據帶到下一個視圖,但圖像不同。 這就是說,如果我點擊一個標題爲「abc」的針,我會在下一個屏幕上成功顯示標題。 但是,如果引腳上的圖像是紅色的,則下一個視圖中的圖像是不同的。
只有第一個和最後一個引腳的圖像才能在下一個視圖中正確顯示。
第二次它給了我第一個圖像,第三次給了我最後一針的圖像。
奇怪。
my didSelectAnnotationCode。
-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
Annotations *annView = view.annotation;
NSLog(@"Pin title in callout = %@",annView.pinTitle);
objOnClickPinView = [[onClickPinView alloc]initWithNibName:@"onClickPinView" bundle:nil];
objOnClickPinView.pinTitleString = annView.pinTitle;
[self presentViewController:objOnClickPinView animated:YES completion:nil];
}
注意:我不需要顯示calloutView。我需要直接點擊mapPin導航。
** ** viewForAnnotation顯示此方法定義..? –
@KumarKl:請檢查編輯的問題。 – iCodeAtApple
你如何在objOnClickPinView中呈現ann.image? –