2013-10-24 21 views
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導航。

+0

** ** viewForAnnotation顯示此方法定義..? –

+0

@KumarKl:請檢查編輯的問題。 – iCodeAtApple

+0

你如何在objOnClickPinView中呈現ann.image? –

回答

2

我得到了錯誤。 我發佈這個答案只是因爲如果在不久的將來你的某個人可能會面臨同樣的愚蠢問題。

我傳遞給下一個視圖的連接字符串被其前一個視圖覆蓋,因此它包含啞元數據。 我

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view { 

想通了這一點通過將相同的代碼,並使用

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control 

是如何將編譯器會知道哪個引腳被竊聽。

因此,我使用的4個不同的joinStrings而不是一個,並且檢查上在didSelect條件如

if ([annView.title isEqualToString:@"xyz"]) { 
     objOnClickPinView.getColorCode = joinString1; 
    } 

else if... 
相關問題