1
Apple의 핵심 위치 문서에 설명 된대로 내 위치 검색 클래스를 설정합니다.핵심 위치가있는 대표단 오류
MyCLControl.h
: MyCLController.m
에서
@protocol MyCLControllerDelegate
@required
- (void)locationUpdate:(CLLocation *)location;
- (void)locationError:(NSError *)error;
@end
@interface MyCLController : NSObject <MyCLControllerDelegate, CLLocationManagerDelegate> {
CLLocationManager *locationManager;
id <MyCLControllerDelegate> delegate;
}
@property (nonatomic, retain) CLLocationManager *locationManager;
@property (strong) id <MyCLControllerDelegate> delegate;
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation;
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error;
- (BOOL) connected;
@end
의 init
및 locationManager:didUpdateToLocation:fromlocation
방법 :
- (id) init {
self = [super init];
if (self != nil) {
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
//locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
}
return self;
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
[self.delegate locationUpdate:newLocation];
}
다음과 내가 그것을 호출 오전 방법입니다 같이
- (void)viewDidLoad {
MyCLController *locationController = [[MyCLController alloc] init];
locationController.delegate = locationController.self;
[locationController.locationManager startUpdatingLocation];
}
- (void)locationUpdate:(CLLocation *)location {
NSLog(@"%@", location);
}
나는 무엇입니까 런타임 오류 [MyCLController locationUpdate:]: unrecognized selector sent to instance
은 일단 [self.delegate locationUpdate:newLocation]
에 도달합니다.
@selector를 (locationUpdate :를 newLocation는) 잘못된 것입니다. 예상되는':'을 제공합니다. 'newLocation' 다음에':'를 추가하면'respondersToSelector'에 대한 인스턴스 메소드가 없습니다. – darksky
@Darksky OK cheers; 내 대답을 업데이트했습니다. – trojanfoe