2013-02-20 4 views
0

내 IOS 응용 프로그램에서 오류가 발생했습니다. Google과 여기에서 검색했지만 특정 솔루션을 찾을 수 없습니다.didUpdateUserLocation보기를 호출하지 않고 다시로드했습니다.

내 app에서 두 순간에 사용하는 mapView라는 viewController가 있습니다.이 뷰에는 MKMapView와 코드가 들어 있습니다. 에서

내 mapView.h가 :

@property (strong, nonatomic) IBOutlet MKMapView *mapSpot; 

그리고 내 mapView.m에있다 :

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    [mapSpot setShowsUserLocation:YES]; 
} 

- (void) mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{  
    MKCoordinateRegion region   = MKCoordinateRegionMakeWithDistance([userLocation coordinate], 500, 500); 
    [mapSpot setRegion:region animated:YES]; 
} 

그래서, 첫 순간에 나는 다른의 ViewController로지도보기를 사용하여로드 :

@property (strong, nonatomic) ViewMap *mapView; 

mapView       = [[ViewMap alloc] initWithNibName:@"ViewMap" bundle:nil]; 
[self.view addSubview:[mapView view]]; 

나는 그 ViewController를 언로드하고 다른 순간에 다른 ViewController에서 MapView를 다시로드하지만 t 그의 순간 방법 : - (void) mapView : (MKMapView *) mapView didUpdateUserLocation : (MKUserLocation *) userLocation이 호출되지 않았습니다.

첫 번째 ViewController가 언로드되었는지 확인합니다.

두 번째 ViewController를로드 할 때 MapView의 새로운 인스턴스가 있지만 대리자 메서드를 호출하지 않습니다.

누구나 알고있는 점이 있습니까?

감사

========================================= =========================

편집 및 처리 :

+1

솔루션을 답변으로 게시하고 자신의 대답을 수락해야합니다. – Jano

+0

답변이 솔루션에 추가되었습니다. 감사합니다. – sidneivl

+0

답변은 어디에 있습니까? 난 문제가되지 않습니다 – Georg

답변

0

문제는 대신,이 라인

[self.view addSubview:[mapView view]]; 

만 컨트롤러 코드가 실행되지 않은보기를 추가하는 경우에, 당신이보기를 추가하는 방법에 당신은 예를 들어, mapView을 제시하는 것을 :

[self presentViewController:mapView animated:YES completion:nil]; 
+0

같은 문제가있어, 내가 사용 presentViewController 문제가 해결되지, 그리고 아이폰 presentViewController 전체보기에서보기를로드하고 내 애플 리케이션에서 불가능합니다. – sidneivl

+0

다른 질문은 처음로드 할 때 완벽하게 작동하는 이유와 동일한보기 작업을 다시로드 할 때 및보기를 변경하면 작동하지 않는 이유는 무엇입니까? 감사 – sidneivl

0

문제는 위, 어쩌면 내가 응용 프로그램을 테스트 시뮬레이터를 사용하고 있기 때문에 발생하고, 시뮬레이터 didUpdateUserLocation하지 위치지도를 변경하지 방법 :

그 코드를 검토 한 후에 클래스를 구성하고 설명서를 읽고 오류가 다시 발생한다는 고유 한 설명입니다.

이제 CLLocationManager를 사용하여 처음 위치를 얻은 후 위치를 가져 왔습니다.

앞으로는 사용자 경로를 추적하는 시스템을 구현하므로 CLLocationManager를 사용해야합니다. 변경 후

mapView.m 코드 :

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    locationManager      = [[CLLocationManager alloc] init]; 
    locationManager.delegate   = self; 
    locationManager.distanceFilter  = kCLDistanceFilterNone; 
    locationManager.desiredAccuracy  = kCLLocationAccuracyBest; 
    [locationManager startUpdatingLocation]; 
} 

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ 
    CLLocation *loc = [locations lastObject]; 

    // store the location to use in any moment, it needs to be checked because the first time when get the coordinate not pass infos to load places according the current position 
    if (!location.latitude) { 
     location       = [loc coordinate]; 

//  set center the map at the current position 
     MKCoordinateRegion region   = MKCoordinateRegionMakeWithDistance(location, 500, 500); 
     [mapSpotView setRegion:region animated:YES]; 

     [[NSNotificationCenter defaultCenter] postNotificationName:@"loadPlaces" object:nil]; 

     [locationManager stopUpdatingLocation]; 
    } 
} 

사람이 더 나은 솔루션이있는 경우, 제발, 여기에 포스트!

그게 전부 야!

관련 문제