Ios 使用Bundle.main.loadNibNamed重用标识符

Ios 使用Bundle.main.loadNibNamed重用标识符,ios,swift,performance,mapbox,Ios,Swift,Performance,Mapbox,我使用的是mapbox sdk,当用户使用它时,我必须向地图添加和删除几个注释。 我在添加大量注释时遇到性能问题。 我猜是因为我不能再次重复使用相同的注释。事实上,我要添加的注释与我删除的注释相同,因此我应该真正重用它们 //reuseIdentifier should be something specific for every single annotation like reuseIdentifier = annotation.latitude var annotationView =

我使用的是mapbox sdk,当用户使用它时,我必须向地图添加和删除几个注释。 我在添加大量注释时遇到性能问题。 我猜是因为我不能再次重复使用相同的注释。事实上,我要添加的注释与我删除的注释相同,因此我应该真正重用它们

//reuseIdentifier should be something specific for every single annotation like reuseIdentifier = annotation.latitude
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseIdentifier) as? MarkerView

if annotationView == nil 
        //How can I both use Bundle.main.loadNibNamed(...) and instance with a custom identifier here
        annotationView = Bundle.main.loadNibNamed("MarkerView", owner: self, options: nil)?.first as? MarkerView

        annotationView!.frame = CGRect(x: 0, y: 0, width: 60, height: 120)

}
问题是,如果我已经从xib文件加载了视图,如何使用自定义标识符执行实例?
这能解决我的性能问题吗?否则,您建议我做什么?

只需为视图提供一个自定义重用标识符,其中包含:

- (NSString *) reuseIdentifier {
   return @"myIdentifier";
}

只需为视图提供一个自定义重用标识符:

- (NSString *) reuseIdentifier {
   return @"myIdentifier";
}