初始化新类时,将自动执行此类的哪些方法..请查看以下代码:
CoreLocationDemoViewController.m
- (void)viewDidLoad {
NSLog(@"CORE_LOCATION_DEMO_VIEW_CONTROLLER=======>VIEW_DID_LOAD");
[super viewDidLoad];
CLController = [[CoreLocationController alloc] init]; // line 1
CLController.delegate = self; // line 2
[CLController.locMgr startUpdatingLocation];
}
CoreLocationController.m
- (id)init {
NSLog(@"CORE_LOCATION_CONTROLLER=======>INIT");
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
NSLog(@"CORE_LOCATION_CONTROLLER=======>DID_UPDATE_TO_LOCATION");
}
从调试开始,我得到了
2011-10-11 23:44:31.682 CoreLocationDemo[77470:207] CORE_LOCATION_CONTROLLER=======>INIT
2011-10-11 23:44:31.707 CoreLocationDemo[77470:207] CORE_LOCATION_CONTROLLER=======>DID_UPDATE_TO_LOCATION
似乎 init 和 locationManager 会自动执行......我对此不太确定......
另一个问题是第2行,
CLController.delegate = self ( delegate is declared as id delegate in CoreLocationController.h )
确实
如果您之前遇到过,请提供帮助,欢迎所有评论
答案 0 :(得分:0)
因为这个
而调用了init()CLController = [[CoreLocationController alloc] init];
由于此作为委托回调,因此调用了didUpdateToLocation
[CLController.locMgr startUpdatingLocation];
作为旁注,我注意到你的init既不会调用super init也不会返回self。我猜你已经减少了这个帖子。