Почему я не могу удалить свои аннотации из mapview?Почему я не могу удалить свои аннотации из mapview?
Мой код:
(аннулируются) viewDidAppear: (BOOL) анимированный { [супер viewDidAppear: анимированные]; [self сталFirstResponder];
NSMutableArray * аннотации = [[NSMutableArray alloc] init];
NSString * path = [[NSBundle mainBundle] pathForResource: @ "data" ofType: @ "plist"]; NSDictionary * dict = [словарь NSDictionaryWithContentsOfFile: путь];
если ([[NSUserDefaults standardUserDefaults] boolForKey: @ "blackKey"]) { NSLog (@ "Черный на");
NSArray * ann = [dict objectForKey: @ "Category1"];
для (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];
не работает для меня
Хорошо, спасибо! A уже удалили аннотации с помощью removeAnnotationS –