2012-07-26 8 views
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 

initlocationManager: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]에 도달합니다.

답변

0

MyCLController을 자신의 대의원으로 설정 했습니까? 틀림없이 대신보기를 위임자로 만들려는 의도였습니까?

당신은 또한 사용 (이 required을 비록) 위임을 확인하는 것이 방법을 지원해야합니다

- (void)locationManager:(CLLocationManager *)manager 
    didUpdateToLocation:(CLLocation *)newLocation 
      fromLocation:(CLLocation *)oldLocation 
{ 
    if ([self.delegate respondsToSelector:@selector(locationUpdate:)]) 
    { 
     [self.delegate locationUpdate:newLocation]; 
    } 
} 
+0

@selector를 (locationUpdate :를 newLocation는) 잘못된 것입니다. 예상되는':'을 제공합니다. 'newLocation' 다음에':'를 추가하면'respondersToSelector'에 대한 인스턴스 메소드가 없습니다. – darksky

+0

@Darksky OK cheers; 내 대답을 업데이트했습니다. – trojanfoe