2014-09-25 54 views
0

我有一個UIViewController代碼啓動位置更新: [locationManager startUpdatingLocation];Objective-C的 - 核心 - 的iOS 7.1

是可以正常使用。但我需要每次退出此屏幕時停止更新位置,並在我返回時重新開始。

第一次更新。在其他時候它不會停止。

代碼退出視圖:

[locationManager stopUpdatingLocation]; 
locationManager.delegate = nil; 

IHAVE也試過:(沒有成功過)

[locationManager stopMonitoringSignificantLocationChanges]; 
[locationManager stopUpdatingHeading]; 
[locationManager stopUpdatingLocation]; 

locationManager.delegate = nil; 
locationManager = nil; 

它總是更新。但從第二次不停止更新。

didUpdateLocation代碼:

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ [self addingMarkerUser]; }

+0

該代碼被稱爲* from *? – Droppy 2014-09-25 11:49:08

+0

從'viewDidDisappear' – Gian 2014-09-25 11:50:51

+0

顯示您的didupdatelocation代碼 – 2014-09-25 11:51:02

回答

-1

你應該把你的代碼在viewDidAppear,我在想你[self addingMarkerUser]你使用類似這樣沒有停止(如果沒有,請提供代碼):

CLGeocoder *geocoder = [[CLGeocoder alloc] init] ; 
    [geocoder reverseGeocodeLocation:_currentLocation completionHandler:^(NSArray *placemarks, NSError *error) { 

if (!(error)) { 
       //do something with the data. 
       //then stop the update. 
      [locationManager stopUpdatingLocation]; 

     } 
    }]; 

如果你這樣做,每當你的視圖出現時,位置將開始更新,然後停止一旦數據檢索。

+0

他問相反 – JustSid 2014-09-25 15:11:23

+0

我不使用地理編碼。只需將設備當前位置的標記放置在地圖上即可。 – Gian 2014-09-25 16:29:29