【问题标题】:Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MKUserLocation tag]:由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[MKUserLocation 标签]:
【发布时间】:2017-11-21 10:28:23
【问题描述】:

我只是比较两个值,但有时应用程序崩溃。如何处理。

NSString *  markerid = [_selectedCoordinate objectForKey:@"markerid"];
    for(CustomAnnotations *annotation in _mapView.annotations){
        if(annotation.tag == [markerid integerValue]){
            [_mapView selectAnnotation:annotation animated:NO];
            return;
        }
    }

【问题讨论】:

  • 我在 viewWillAppear 中运行代码。
  • 给它下断点...
  • 异常断点,具体来说。
  • One/many/all annotation 是 MKUserLocation 类的对象,而不是 CustomAnnoation 的对象,这就是它崩溃的原因。

标签: ios objective-c location


【解决方案1】:

地图注解也包含用户位置注解,检查[annotation class] != [MKUserLocation class]或[annotation class] == [CustomAnnoation class]然后获取注解的标签

NSString *  markerid = [_selectedCoordinate objectForKey:@"markerid"];
for(CustomAnnotations *annotation in _mapView.annotations){
    if([annotation class] != [MKUserLocation class]) {
        if(annotation.tag == [markerid integerValue]) {
            [_mapView selectAnnotation:annotation animated:NO];
            return;
        }
    }
}

【讨论】:

    猜你喜欢
    • 2018-04-05
    • 2013-04-27
    • 2021-09-17
    • 2012-07-12
    • 2021-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多