MKMapView viewForAnnotation不在iOS 8中调用

时间:2014-10-25 11:30:04

标签: objective-c xcode ios8 mkmapview mkmapviewdelegate

在iOS 8中未调用的MKMapView委托方法。 在viewDidLoad中:

CGRect mapViewFrame = CGRectMake(0.0, 129.0, 320.0, 419.0);
    _mapView = [[MKMapView alloc] initWithFrame:mapViewFrame];
    [_mapView setMapType:MKMapTypeStandard];
    [_mapView setDelegate:self];
    [_mapView setShowsUserLocation:YES];

永远不会调用这些方法:

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{};

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {}

在iOS 8的早期版本中,一切正常。

2 个答案:

答案 0 :(得分:0)

我认为iOS 8中的用户位置检索已更改。现在您需要使用CLLocationManager授权来跟踪用户位置。 mapView.showsUserLocation = YES已经不够了。

您需要一个CLLocationManager实例:

@property(nonatomic, strong) CLLocationManager *locationManager;

在viewDidLoad

self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
    [self.locationManager requestWhenInUseAuthorization];
}
[self.locationManager startUpdatingLocation];
// your mapKit stuff...

这应该开始跟踪用户的位置并调用委托方法。

答案 1 :(得分:0)

您是否尝试过添加其他注释(而非用户位置)并查看是否调用了委托方法?这将有助于您解决问题