2016-09-07 5 views
0

내 앱에서 위치 데이터를 다운로드하고지도에 표시하고 있습니다. 왜 그들이 일어나고 있는지 이해할 수없는 몇 가지 시나리오가 있습니다. 때로는 내 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은이 경우에 때때로 호출되며 마커를 볼 수 없습니다. 지도에서).

enter image description here

나는 스택 트레이스에서 많은 정보를 얻을 수 없었다. mapVc가 때때로 할당 해제되는 이유를 알고 싶습니다. 내 mapVc가 언제든지 할당 해제되지 않도록하는 방법은 무엇입니까?

편집 :

<MapVc: 0x7ff83f2883c0> On didAppear 

<MapVc: 0x7ff83f2883c0> on dealloc (why is this happening ?) 

<MapVc: 0x7ff84475b6f0> new instance again on viewDidAppear 

답변

1

어떻게 내 mapVc 언제든지 해제되어 있지 않은지 확인하기 :

내가 할당 해제의 경우에 mapVc 자기 기록?

VC가 화면에 없거나 (적어도 탐색 스택에있을 때) 필요하면 MVC가 손상된 것입니다. 나는 그것이 여기서 일어나는 일이 아니라고 생각하지만 마음에 두는 것이 중요합니다. 모델 계층에서 네트워크 작업이 수행되고 뷰 계층에서 모델을 관찰해야합니다. 뷰 컨트롤러는 네트워크 작업이 아닌 현재 표시되는 뷰를 관리합니다. 보기 컨트롤러를 잘못 구성했을 가능성이 높습니다.

즉, 아마도이 경우 실제 문제는 아닙니다. 문제는 아무 것도 보유하고 있지 않다는 것입니다. mapVc. 루트 뷰 컨트롤러에 weak입니다. 따라서 segue가 완료 되 자마자 곧 릴리스됩니다 (segue는 실행 중일 때 segue를 유지합니다). mapVc이 루트보기 컨트롤러에 내장되어 있으면 거의 확실하게 strong이어야합니다.