正确的例子:
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
Run Code Online (Sandbox Code Playgroud)
错误的例子:
- (void)dealloc {
[super dealloc];
[viewController release];
[window release];
}
Run Code Online (Sandbox Code Playgroud)
在覆盖一个方法的过程中几乎所有其他情况下我首先会调用super的方法实现,在这种情况下,apple总是在最后调用[super dealloc].为什么?
我没有在sim或设备上获得任何位置回调.我已经调用了这个代码:
- (void)startLocationCallbacks: (NSObject*) ignore
{
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
locationManager.distanceFilter = MINIMUM_METERS;
[locationManager startUpdatingLocation];
NSLog(@"[DEBUG] [locationManager startUpdatingLocation] (%@, %@)", locationManager, locationManager.delegate);
}
Run Code Online (Sandbox Code Playgroud)
并在两者的顶部记录日志
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
Run Code Online (Sandbox Code Playgroud)
和
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
Run Code Online (Sandbox Code Playgroud)
但是这两个日志语句都没有被调用.为我的应用启用了位置通知(如设置中所示,加上我说"允许".)
我没有获得位置更新的可能原因是什么?
配置/其他信息:
谢谢!
所以现在我至少得到以下代码的回调...
- (void)viewDidLoad {
[super viewDidLoad];
mapView=[[MKMapView alloc] initWithFrame:self.view.frame];
//mapView.showsUserLocation=TRUE;
mapView.delegate=self;
[self.view insertSubview:mapView atIndex:0];
NSLog(@"locationServicesEnabled: %@", [CLLocationManager locationServicesEnabled] ? @"YES":@"NO");
CLLocationManager *newLocationManager = [[CLLocationManager alloc] init];
[newLocationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[newLocationManager setDistanceFilter:kCLDistanceFilterNone];
[self setLocationManager:newLocationManager];
[[self locationManager] setDelegate:self];
[[self locationManager] startUpdatingLocation];
NSLog(@"Started updating Location");
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
NSLog(@"Did update to location");
mStoreLocationButton.hidden=FALSE;
location=newLocation.coordinate;
MKCoordinateRegion region;
region.center=location;
MKCoordinateSpan span;
span.latitudeDelta=0.01;
span.longitudeDelta=0.01;
region.span=span;
[mapView setRegion:region animated:TRUE];
}
Run Code Online (Sandbox Code Playgroud)
我可以在第二种方法中设置断点,NSLog报告连续的位置更新,但由于某种原因,带有span的缩放不起作用.知道为什么吗?它有我的坐标和一切.在这一个上刮我的头.