【问题标题】:Method not getting called (Core Location) Cocoa Touch方法没有被调用(核心位置)Cocoa Touch
【发布时间】:2011-07-13 16:59:18
【问题描述】:

大家好, 我正在尝试调用更新方法,但它不起作用,知道吗?

#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 
{ 

}

【问题讨论】:

    标签: iphone methods sdk call core-location


    【解决方案1】:

    didUpdateToLocation 将在位置更改时被调用。

    我猜你是在模拟器中测试它,而在模拟器上,位置没有发生变化,所以不会调用该方法。

    建议 你应该执行other delegate methods 来检查发生了什么;以防万一出现错误。例如:locationManager:didFailWithError:

    【讨论】:

      猜你喜欢
      • 2010-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多