由于未捕获的异常 'NSInvalidArgumentException',正在终止应用程序,原因:'-[MKUserLocation 标记]:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MKUserLocation tag]:

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

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

地图注释也包含用户位置注释,检查[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;
        }
    }
}