为什么我无法从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];
对我不起作用
好的,谢谢! A已经使用removeAnnotationS删除了注释 –