2012-06-01 60 views
0

爲什麼我無法從mapview中刪除我的註釋?爲什麼我無法從mapview中刪除我的註釋?

我的代碼:

  • (無效)viewDidAppear:(BOOL)動畫{ [超級viewDidAppear:動畫]; [self becomeFirstResponder];

    NSMutableArray * annotations = [[NSMutableArray alloc] init]; NSString * path = [[NSBundle mainBundle] pathForResource:@「data」ofType:@「plist」]; NSDictionary * dict = [NSDictionary dictionaryWithContentsOfFile:path];如果([[NSUserDefaults standardUserDefaults] boolForKey:@「blackKey」]) { NSLog(@「Black is on」);

    NSArray * ann = [dict objectForKey:@「Category1」];

    的for(int i = 0;我< [安計數];我++){

    NSString *coordinates = [[ann objectAtIndex:i] objectForKey:@"Coordinates"]; 
    
    double realLatitude = [[[coordinates componentsSeparatedByString:@","] objectAtIndex:1] doubleValue]; 
    double realLongitude = [[[coordinates componentsSeparatedByString:@","] objectAtIndex:0] doubleValue]; 
    
    MyAnnotation *myAnnotation = [[MyAnnotation alloc] init]; 
    CLLocationCoordinate2D theCoordinate; 
    theCoordinate.latitude = realLatitude; 
    theCoordinate.longitude = realLongitude; 
    
    myAnnotation.coordinate=CLLocationCoordinate2DMake(realLatitude,realLongitude); 
    
    myAnnotation.title = [[ann objectAtIndex:i] objectForKey:@"Name"]; 
    myAnnotation.subtitle = [[ann objectAtIndex:i] objectForKey:@"Address"]; 
    myAnnotation.icon = [[ann objectAtIndex:0] objectForKey:@"Icon"]; 
    
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"blackKey"]) 
    { 
        NSLog(@"Black is on"); 
        [mapView addAnnotation:myAnnotation]; 
        [annotations addObject:myAnnotation]; 
    
    } else 
        { 
         NSLog(@"Black is off"); 
    
         [self.mapView removeAnnotation:myAnnotation]; 
    
    
        } 
    
    } 
    

    }

    別的 { //什麼也不做 }

    } 
    

[self.mapView removeAnnotation:myAnnotation];對我不起作用

回答

0

沒有什麼可以刪除的。您創建註釋,然後基於blackKey的檢查,您可以添加或刪除它。但是,當你刪除它時,你從未在此之前添加它。

+0

好的,謝謝! A已經使用removeAnnotationS刪除了註釋 –