【发布时间】:2011-10-13 05:52:55
【问题描述】:
首先请看下面的代码
CoreLocationController.h
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
@protocol CoreLocationControllerDelegate // Line 1
@required
- (void)locationUpdate:(CLLocation *)location;
- (void)locationError:(NSError *)error;
@end
/* Declare class named CoreLocationControll and inherited from CLLocationManagerDelegate */
@interface CoreLocationController : NSObject <CLLocationManagerDelegate> {
CLLocationManager *locMgr;
id delegate;
}
@property (nonatomic, retain) CLLocationManager *locMgr; // claim setter and getter for locMgr
@property (nonatomic, assign) id delegate; // claim setter and getter for delegate
@end
CoreLcationController.m
#import "CoreLocationController.h"
@implementation CoreLocationController
@synthesize locMgr, delegate;
/* Is triggered by - (void)startUpdatingLocation from CoreLocationDemoViewController.m*/
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
NSLog(@"CORE_LOCATION_CONTROLLER=======>DID_UPDATE_TO_LOCATION");
if([self.delegate conformsToProtocol:@protocol(CoreLocationControllerDelegate)]) // line 2
[self.delegate locationUpdate:newLocation];
}
我的问题是第 1 行和第 2 行做什么以及为什么 我查了 CoreLocationControllerDelegate 但没有参考
【问题讨论】:
-
不清楚你的问题是什么,能具体点吗?
-
糟糕,这是我的错...我的问题是 line1 和 line2 的作用以及我们必须使用它的原因...
-
哦,我没有注意到代码中的第1行和第2行cmets!好的。
标签: iphone objective-c ios core-location