gpt4 book ai didi

ios - 通过 Bundle.main.loadNibNamed 重用标识符

转载 作者:行者123 更新时间:2023-11-28 08:01:39 24 4
gpt4 key购买 nike

我正在使用 mapbox sdk,当用户使用它时,我必须在 map 上添加和删除几个注释。添加大量注释时出现性能问题。我想是因为我不能再次重用相同的注释。事实上,我必须添加的注释与我删除的注释相同,所以我真的应该重用它们。

//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 文件加载 View ,如何使用自定义标识符实例化?这会解决我的性能问题吗?否则你有什么建议?

最佳答案

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

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

关于ios - 通过 Bundle.main.loadNibNamed 重用标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46500865/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com