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

Reuse identifier with Bundle.main.loadNibNamed

我正在使用 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";
}