2012-05-10 3 views
0

У меня есть приложение, в котором я использую MapView, и у меня есть 4 типа MKAnnotation. У меня также есть 4 кнопки на экране. каждая кнопка должна показывать или скрывать один из типов MKannotation. Я могу отслеживать типы и удалять them.but, когда я пытаюсь добавить любую MKannotation, я получаю сообщение об ошибке. после поиска я нашел аналогичную проблему, на которую не ответил.Добавление и удаление MKAnnotation с точки зрения карты

An instance 0x6ec5750 of class MapPoint was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. 

ios5 removing annotation from a mapview

первую очередь я буду добавлять MKAnnotation от после вызова веб-службы:

for (int x=0; x<PromotionsArray.count; x++) 
{ 
    Promotion *pr = [PromotionsArray objectAtIndex:x]; 
    CLLocationCoordinate2D newCoord ={ pr.promotionLatitude, pr.promotionLongitude}; 
    MapPoint *mp= [[MapPoint alloc] initWithCoordinate:newCoord]; 
    mp.currentTitle=pr.PromotionTitle; 
    mp.currentSubTitle=pr.RetailerName; 
    mp.currentPromotionArrayID=[NSString stringWithFormat:@"%d",x]; 
    mp.currentRetailerID = pr.RetailerID; 
    mp.currentPromotionType = pr.PromotionType; 
    [mapView addAnnotation:mp]; 
} 

теперь у меня есть 4 кнопки на взгляд человека. Type1, Type2, Type3 и Type4. если я нажимаю на кнопку Type1 он удалит все MKAnnotation из Type1, используя следующий код, который работает отлично:

for (id <MKAnnotation> myAnnot in [mapView annotations]) 
    { 
     if (![myAnnot isKindOfClass:[MKUserLocation class]]) 
     { 
      if([(MapPoint *)myAnnot currentPromotionType]==PromotionType1) 
      { 
       NSLog(@"Hiding All Type1 Annotations"); 
       [mapView removeAnnotation:myAnnot]; 
      } 
     } 
    } 

теперь, если я хочу снова показать Type1, я использую следующий код, который вызывает проблему :

for (int x=0; x<PromotionsArray.count; x++) 
    { 
     Promotion *pr = [PromotionsArray objectAtIndex:x]; 
     if (pr.promotionType==PromotionType1) 
     { 
      CLLocationCoordinate2D newCoord ={ [pr.promotionLatitude doubleValue],[pr.promotionLongitude doubleValue]}; 
      MapPoint *map= [[MapPoint alloc] initWithCoordinate:newCoord]; 
      map.currentTitle=pr.PromotionTitle; 
      map.currentSubTitle=pr.RetailerName; 
      map.currentPromotionArrayID=[NSString stringWithFormat:@"%d",x]; 
      [mapView addAnnotation:map]; 
     } 
    } 

проблема появляется в этой строке [MAPview addAnnotation: карта]; , которая вызывает сообщение об ошибке я упоминал relier (здесь это снова)

An instance 0x6ec5750 of class MapPoint was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. 
+0

Что говорит об ошибке? – bbarnhart

+1

Да, что именно представляет собой сообщение об ошибке и отправляет код, в который вы добавляете аннотацию. Если ошибка «освобождена, а наблюдатели с ключевыми значениями все еще зарегистрированы», это может произойти, поскольку координаты аннотации недействительны. – Anna

+0

ошибка такая же, как и в ссылке. Я обновил вопрос с сообщением об ошибке. – Kassem

ответ

0

работы в настоящее время, проблема заключается в совершенно другом методе. я пытался преобразовать двойное значение NSString, делая это:

[Nsstring stringWithFormat:@"%d",doubleVal]; 

% D должно быть% е !!!!! это была глупая небольшая ошибка. спасибо за помощь и @AnnaKarenina за подсказку

0
// REMOVING ALL ANNOTATION 
    for (id <MKAnnotation> myAnnot in [objMapView annotations]) 
    { 
     if (![myAnnot isKindOfClass:[MKUserLocation class]]) 
     { 
      [objMapView removeAnnotation:myAnnot]; 
     } 
    }