相关疑难解决方法(0)

为什么我必须最后调用super -dealloc,而不是先调用?

正确的例子:

- (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].为什么?

iphone cocoa-touch memory-management uikit

29
推荐指数
3
解决办法
2万
查看次数

为什么我的CLLocationmanager委托没有被调用?

我没有在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)

但是这两个日志语句都没有被调用.为我的应用启用了位置通知(如设置中所示,加上我说"允许".)

我没有获得位置更新的可能原因是什么?

配置/其他信息:

  • 我已经分配了locationManager,并将其保存在retain属性中.
  • 我调用了startUpdatingLocation
  • 我正在使用4.1 SDK
  • Sim和iPod-touch(第二代)和iPhone-3都存在问题,全部运行4.1
  • 我的应用程序中允许使用位置通知(两者都在"设置"中指示,因为我在警报中单击了"允许".)
  • 我以前成功使用过CLLocationManager(在许多运送应用程序中!)这对我来说是一个真正的拔毛器.

谢谢!

iphone cllocationmanager

20
推荐指数
2
解决办法
2万
查看次数

CLLocationManager startUpdatingLocation不起作用

所以现在我至少得到以下代码的回调...

- (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的缩放不起作用.知道为什么吗?它有我的坐标和一切.在这一个上刮我的头.

iphone zoom mkmapview cllocationmanager ios

8
推荐指数
3
解决办法
2万
查看次数