내 앱에서 위치 데이터를 다운로드하고지도에 표시하고 있습니다. 왜 그들이 일어나고 있는지 이해할 수없는 몇 가지 시나리오가 있습니다. 때로는 내 mapView (Google지도) 클래스 dealloc
이 호출되어지도에서 마커를 볼 수 없지만 여전히 내 현재 위치를 볼 수 있습니다.dealloc 프로세스를 관찰하는 방법
[ContainerVc] -embedSegue->[MapView]
컨테이너 VC 루트 VC입니다 : 내지도보기 스토리 보드에서 설정이 얼마나
이입니다.
내 rootVc 클래스의
:@property (weak, nonatomic) MapVc *mapVc;
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([[segue identifier] isEqualToString: @"embeddedMapVc"]) {
self.mapVc = [segue destinationViewController];
self.mapVc.delegate = self;
}
}
내 mapVC 클래스 (모든 속성이 강한 비 원자이다) :
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[self setupMapView];
}
- (void)setupMapView{
MyLog(@"Map view just refreshed/setup");
//set map view
self.infoWindow = [[MyMapInfoWindow alloc] initWithFrame:CGRectMake(0, 0, 210, 47)];
self.infoWindow.delegate = self;
CLLocation *center = [[MyLocationMonitor sharedInstance] getLocation];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:center.coordinate.latitude longitude:center.coordinate.longitude zoom:18];
self.mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
self.mapView.camera=camera;
[self.mapView setMapType:kGMSTypeNormal];
[self.mapView setMinZoom:14 maxZoom:18];
[self.mapView setDelegate:self];
self.mapView.myLocationEnabled=YES;
self.mapView.settings.rotateGestures = NO;
self.mapView.settings.myLocationButton = YES;
[self.mapView setPadding:UIEdgeInsetsMake(0, 0, 62, 0)];
self.view = self.mapView;
[self setupMarkers];
}
- (void)setupMarkers{
MyLog(@"setting up markers");
self.annotations = nil;
[self.mapView clear];
[[MyLocationMonitor sharedInstance] getBuildingsWithCompletion:^(BOOL success, NSArray *buildings) {
self.buildings = buildings;
MyLog(@"_buildings_: %@", self.buildings);
if (success) {
GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] init];
self.annotations = [[NSMutableArray alloc] init];
for (NSDictionary *location in buildings) {
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake([[location objectForKey:@"Latitude"] doubleValue], [[location objectForKey:@"Longitude"] doubleValue]);
bounds = [bounds includingCoordinate:coordinate];
GMSMarker *marker = [GMSMarker markerWithPosition:coordinate];
marker.title = [location objectForKey:@"name"];
marker.map = self.mapView;
marker.icon = [UIImage imageNamed:@"Boost-BuildingMarkerIcon"];
marker.userData = @{@"building":location};
marker.infoWindowAnchor = CGPointMake(1.0f, -0.1f);
marker.opacity = 1.0;
[self.annotations addObject:marker];
}
[self.mapView animateWithCameraUpdate:[GMSCameraUpdate fitBounds:bounds withPadding:50.0]];
}
}];
}
-(void)dealloc{
MyLog(@"MApVC dealloc called");
}
그래서, rootVc
에서 내가 다른 컨트롤러로 이동 네트워크 호출이 끝난 후 prepareForSegue
가 호출되고 mapVc 클래스로 이동하고 mapView를 설정하는 rootVc로 컴백합니다 (이 프로세스에서 mapVc dealloc은이 경우에 때때로 호출되며 마커를 볼 수 없습니다. 지도에서).
나는 스택 트레이스에서 많은 정보를 얻을 수 없었다. mapVc가 때때로 할당 해제되는 이유를 알고 싶습니다. 내 mapVc가 언제든지 할당 해제되지 않도록하는 방법은 무엇입니까?
편집 :
<MapVc: 0x7ff83f2883c0> On didAppear
<MapVc: 0x7ff83f2883c0> on dealloc (why is this happening ?)
<MapVc: 0x7ff84475b6f0> new instance again on viewDidAppear