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

时间:2017-09-30 08:09:03

标签: ios swift performance mapbox

我正在使用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文件加载视图,如何使用自定义标识符实例? 这会解决我的性能问题吗?不然你有什么建议吗?

1 个答案:

答案 0 :(得分:0)

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

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