【问题标题】:MKMapView viewForAnnotation not call in iOS 8MKMapView viewForAnnotation 不在 iOS 8 中调用
【发布时间】:2014-10-25 11:30:04
【问题描述】:

在 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 版本中一切正常。

【问题讨论】:

  • 遇到同样的问题!!

标签: objective-c xcode ios8 mkmapview mkmapviewdelegate


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    我认为用户位置检索在 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...
    

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

    【讨论】:

      猜你喜欢
      • 2012-09-25
      • 2012-06-02
      • 1970-01-01
      • 1970-01-01
      • 2015-02-16
      • 2016-07-15
      • 1970-01-01
      • 2014-11-20
      • 1970-01-01
      相关资源
      最近更新 更多