2012-10-11 23 views
1

我試圖調試一個問題,我的代碼MKAnnotationView上的引腳最初在第一次調用時顯示第一次,但是當地圖放大位置時,除用戶位置以外的所有註釋消失。有人可以指出我的邏輯有缺陷嗎?MKAnnotationView問題,我的針腳最初顯示然後消失?

下面是正在使用的代碼。 AddPlacemark用於獲取我所有註釋的位置,然後MKAnnotationView應該將它們全部顯示在地圖上。就像我說過的那樣,當地圖第一次出現時,所有的註釋都會顯示,但是當地圖放大用戶的位置時,所有其他註釋都消失。我相信這個問題纔開始出現的,當我更新了我的Xcode,這樣我可以測試在iOS 6,並得到模擬器爲iPhone 5

- (void)AddPlacemark { 
     if([allplacemarkarray count]>0) { 
     [mapView removeAnnotations:allplacemarkarray]; 

     [allplacemarkarray removeAllObjects]; 
    } 

    MKCoordinateRegion region; 
    MKCoordinateSpan span; 
    span.latitudeDelta=0.2; 
    span.longitudeDelta=0.2; 

    CLLocationCoordinate2D location1; 
    location1.latitude = appdel.MyCurrentLocation.latitude; 
    location1.longitude = appdel.MyCurrentLocation.longitude; 
    region.span = span; 
    region.center = location1; 

    Placemark *addAnnotation = [[[Placemark alloc] initWithCoordinate:location1] retain]; 
    [mapView addAnnotation:addAnnotation]; 
    [allplacemarkarray addObject:addAnnotation]; 
    [addAnnotation release]; 

    if(alllocationArray) { 
     for(int i=0;i<[alllocationArray count];i++) { 
      NSDictionary *locationdict=[alllocationArray objectAtIndex:i]; 
      CLLocationCoordinate2D location; 
      location.latitude = [[locationdict objectForKey:@"VLATITUDE"] floatValue]; 
      location.longitude =[[locationdict objectForKey:@"LONGITUDE"]floatValue]; 
      region.span=span; 
      region.center=location; 

      Placemark *addAnnotation = [[[Placemark alloc] initWithCoordinate:location] retain]; 
      [allplacemarkarray addObject:addAnnotation]; 
      addAnnotation.titletext = [locationdict objectForKey:@"NAME"]; 
      addAnnotation.logoText = [locationdict objectForKey:@"LOGO"]; 
      NSString *add1=[locationdict objectForKey:@"ADDR1"]; 
      NSString *add2=[locationdict objectForKey:@"ADDR2"]; 
      NSString *city=[locationdict objectForKey:@"CITY"]; 
      NSString *state=[locationdict objectForKey:@"STATE"]; 
      NSString *zip =[locationdict objectForKey:@"ZIP"]; 
      addAnnotation.subtitletext=[NSString stringWithFormat:@"%@ %@ %@, %@ %@",add1,add2,city,state,zip]; 
      [addAnnotation setPlacemarkId:[NSNumber numberWithInt:i]]; 
      [mapView addAnnotation:addAnnotation]; 

      [addAnnotation release]; 
      } 

      [mapView setRegion:region animated:TRUE]; 
      [mapView regionThatFits:region]; 
     } 
    } 

    - (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(Placemark *) annotation { 
     MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"MyPin"]; 

     annView.animatesDrop = TRUE; 
     annView.canShowCallout = YES; 
     [annView setSelected:YES]; 

     UIImage *pinImage = [UIImage imageNamed:annotation.logoText]; 
     UIImageView *logoView = [[UIImageView alloc] initWithImage:pinImage]; 

     logoView.frame = CGRectMake(-23, -6, 63, 48); 

     UIButton *myDetailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
     myDetailButton.frame = CGRectMake(0, 0, 23, 23); 
     myDetailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 
     myDetailButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; 
     [myDetailButton addTarget:self action:@selector(checkButtonTapped:) forControlEvents:UIControlEventTouchUpInside]; 
     [myDetailButton setTag:[annotation.placemarkId intValue]]; 
     annView.rightCalloutAccessoryView=myDetailButton; 

     if(annotation.coordinate.latitude == appdel.MyCurrentLocation.latitude && annotation.coordinate.longitude == appdel.MyCurrentLocation.longitude) { 
      annView.pinColor = MKPinAnnotationColorRed; 
     } else if ([annotation.logo isEqualToString:@""]) { 
      annView.pinColor = MKPinAnnotationColorPurple; 
     } else { 
      [annView addSubview:logoView]; 
     } 

     annView.calloutOffset = CGPointMake(-5, 5); 

     return annView; 
    } 
+0

你有沒有實現 - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)動畫? – yunas

+0

@yunas - 我沒有實現,因爲我實現了Annotation的mapView。我不認爲我需要實現另一個mapView,讓我試試這個,讓你知道發生了什麼。感謝您的迴應! –

回答

0

這個問題其實不是由於應用程序錯誤代碼。對於那個很抱歉!原來我的後端代碼將信息提供給這個邏輯很糟糕。

相關問題