2011-03-11 117 views
0

嘿傢伙, 我想調用更新方法,但它不工作,任何想法?方法沒有被調用(核心位置)可可觸摸

#import "TrackerViewController.h" 

@implementation TrackerViewController 

-(IBAction)updateButton:(id)sender{ 
    [self update]; 
    } 

-(void)update{ 
    locmanager = [[CLLocationManager alloc] init]; 
    [locmanager setDelegate:self]; 
    [locmanager setDesiredAccuracy:kCLLocationAccuracyBest]; 

    [locmanager startUpdatingLocation]; 


} 


-(void)viewDidLoad { 
    [self update]; 
} 

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
{ 
    CLLocationCoordinate2D loc = [newLocation coordinate]; 

    latitude.text = [NSString stringWithFormat: @"%f", loc.latitude]; 
    longtitude.text = [NSString stringWithFormat: @"%f", loc.longitude]; 


} 

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error 
{ 

} 

回答

1

當位置發生變化時,將調用didUpdateToLocation

我想你是在模擬器上測試它,並在模擬器上沒有發生位置變化,所以該方法不叫。

建議您應該執行other delegate methods檢查發生了什麼;如果有一些錯誤。例如:locationManager:didFailWithError: