每当初始化MKMapView并将其设置为某个位置
- (void) setMapLocationItem:(Location*)geofence{
if(self.mapView==nil){
self.mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
[self.mapView setDelegate:self];
[self.view addSubview:self.mapView];
[self.view sendSubviewToBack:self.mapView];
[self.view sendSubviewToBack:self.collectionView];
}
[self.mapView setHidden:NO];
[_mapView removeAnnotations:_mapView.annotations];
CLLocationCoordinate2D coordinate;
coordinate= CLLocationCoordinate2DMake(geofence.latitude.doubleValue, geofence.longitude.doubleValue);
CGFloat radius = 110;
if([geofence.radius boolValue])
radius = [geofence.radius floatValue];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance (coordinate, radius, radius);
[_mapView setRegion:region animated:NO];
self.annotation = [[MKPointAnnotation alloc] init];
self.annotation.coordinate = coordinate;
self.annotation.title = geofence.name;
self.annotation.subtitle = geofence.address;
[_mapView addAnnotation:self.annotation];
}
每当viewController关闭时,我使用的内存都不会被释放。
只有在初始化另一个MKMapView时才会释放它。任何想法也是为什么这是? 我在这个问题iOS6 MKMapView Memory Issue
中提到了解决方案