1

我必须在 iPhone OS 4.0 中运行我的应用程序。(在模拟器中)。

-(BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self newLocationUpdate];
}

-(void)newLocationUpdate
{
    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    [locationManager startUpdatingLocation];

}

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation 
{
    [locationManager stopUpdatingLocation];
}

在这个 CLLocationManager 委托方法没有被调用。我们应该进行哪些更改才能调用委托方法?

4

1 回答 1

3

我怀疑您的“locationManager”实例过早释放。

是财产吗?如果是这样,则更改为:

locationManager = [[CLLocationManager alloc]] init];

至:

self.locationManager = [[CLLocationManager alloc] init];

并确保声明该属性:

@property (nonatomic, retain) CLLocationManager * locationManager;

并且不要忘记稍后在适当的时候发布它。

于 2010-07-23T22:52:16.610 回答