0
當初始化一個新的類,這個類的方法將被自動執行。請看看下面的代碼:問題有關iOS的核心位置GPS
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。米
- (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
似乎初始化和的LocationManager自動執行......我不敢肯定這個...
另一個問題是,在第2行,
CLController.delegate = self (delegate is declared as id delegate in CoreLocationController.h)
做什麼
如果您以前遇到過,請在此提供幫助,並歡迎所有意見
是的,我確實修剪了一些線條。謝謝你的評論。我現在比較好.. –
第2行如何... –
由於您正在調用CLLocationManager(locMgr)的startUpdatingLocation,因此您沒有直接調用didUpdateToLocation,所以locationmanager在獲取locationFix時會調用委託方法didUpdateToLocation 。閱讀[this](http://developer.apple.com/library/ios/#DOCUMENTATION/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html)和http://developer.apple.com/library/ios/#文檔/ CoreLocation /參考/ CLLocationManagerDelegate_Protocol/CLLocationManagerDelegate/CLLocationManagerDelegate.html。一般閱讀委託如何工作。 – Saran