1

コアの場所は機能しますが、このコード行で警告が表示されます。locationManager.delegate = 自己; 警告は、互換性のない型 '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.
}
4

2 に答える 2

6

ロケーション マネージャーのデリゲートのプロトコルを実装するクラスを宣言します。

@interface phoneLocationViewController : UIViewController <CLLocationManagerDelegate> {
于 2012-09-07T13:44:51.033 に答える
3

CLLocationManagerDelegateインターフェイス宣言に を追加する必要があります。

@interface phoneLocationViewController : UIViewController <CLLocationManagerDelegate> {
    ....
}
于 2012-09-07T13:45:05.453 に答える