2012-09-07 76 views
1

我的核心位置有效,但我在此行代碼處收到警告。 locationManager.delegate = self;警告是從不兼容類型'phoneLocationViewController * const __strong'分配給'id'。我如何擺脫這個警告?這裏是我的代碼核心位置警告問題

.H

@interface phoneLocationViewController : UIViewController { 

} 

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation  
*)newLocation fromLocation:(CLLocation *)oldLocation; 

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error; 



@property (nonatomic, retain) CLLocationManager *locationManager; 
@property (nonatomic, retain) CLLocation *currentLocation; 

.M

@synthesize locationManager, currentLocation; 

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation 
*)newLocation fromLocation:(CLLocation *)oldLocation { 
self.currentLocation = newLocation; 

if(newLocation.horizontalAccuracy <= 100.0f) { [locationManager stopUpdatingLocation]; } 
} 

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { 
if(error.code == kCLErrorDenied) { 
    [locationManager stopUpdatingLocation]; 
} else if(error.code == kCLErrorLocationUnknown) { 
    // retry 
} else { 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error retrieving location" 
                message:[error description] 
                delegate:nil 
              cancelButtonTitle:@"OK" 
              otherButtonTitles:nil]; 
    [alert show]; 
} 
} 

- (void)viewDidLoad 
{ 
locationManager = [[CLLocationManager alloc] init]; 
locationManager.delegate = self; (I GET THE WARNING HERE) 
[locationManager startUpdatingLocation]; 

[super viewDidLoad]; 
// Do any additional setup after loading the view, typically from a nib. 
} 

- (void)viewDidUnload 
{ 
[locationManager stopUpdatingLocation]; 

[super viewDidUnload]; 
// Release any retained subviews of the main view. 
} 
+0

我想知道爲什麼這個問題downvoted?從我+1來平衡。 –

回答

6

聲明類爲實現外景經理的委託協議。

@interface phoneLocationViewController : UIViewController <CLLocationManagerDelegate> { 
+0

謝謝你的工作 –

3

您應該CLLocationManagerDelegate添加到您的接口聲明。

@interface phoneLocationViewController : UIViewController <CLLocationManagerDelegate> { 
    .... 
} 
+0

謝謝你的工作 –