比较糊涂的autorelease

来源:互联网 发布:游戏特效软件 编辑:程序博客网 时间:2024/05/16 08:58

在学习iphone定位api的时候,由于偷懒,在方法调用的时候 省略了self,如下:

- (void)viewDidLoad {

    [super viewDidLoad];

clManager = [[[CLLocationManager alloc] init] autorelease];//如果改成self.clManager = [[[CLLocationManager allocinit]                                                                                                      //autorelease];则没有问题

clManager.delegate = self;

[clManager startUpdatingLocation];

}

 

因为调用了autorelease,而clManager没有加self前缀,导致[clManager startUpdatingLocation];调用无法激活代理函数的调用(- (void)locationManager:(CLLocationManager *)manager

didUpdateToLocation:(CLLocation *)newLocation

  fromLocation:(CLLocation *)oldLocation)

 

 

解决方案,要么去掉autorelease,要么增加self。

原创粉丝点击