2011-03-11 64 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: