gpt4 book ai didi

ios - 在 Cell 中使用 MKMapView 时内存泄漏

转载 作者:行者123 更新时间:2023-11-28 05:34:16 25 4
gpt4 key购买 nike

我想在 SideView 中使用 MKMapView。 SideView 包含一些单元格,我像这样加载 MapView:(这是我的自定义 UITableViewCell 类)

override init(style: UITableViewCellStyle, reuseIdentifier: String) {
super.init(style: style, reuseIdentifier: "AddressCell")

var addressMap = MKMapView(frame: CGRectMake(0,50,250,150))

var latitude:CLLocationDegrees = 48.399193
var longitude:CLLocationDegrees = 9.993341
var latDelta:CLLocationDegrees = 0.01
var longDelta:CLLocationDegrees = 0.01

var theSpan:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, longDelta)
var churchLocation:CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)

var theRegion: MKCoordinateRegion = MKCoordinateRegionMake(churchLocation, theSpan)

addressMap.setRegion(theRegion, animated: true)

self.contentView.addSubview(addressMap)

这里的问题是, map 中的内存永远不会被释放。我如何在 UITableViewCell 中使用 map 而不会出现内存问题?

最佳答案

好的,如果您仍在寻找解决方案,我发现在离开 mapView 时(或在任何事件重新加载 MapKit View 之前)调用 removeFromSuperview() 会释放内存。简单地添加

override func viewDidDisappear(animated: Bool) {
myMap.removeFromSuperview()
}

我的 MapKit View 的 View Controller 足以为我解决这个问题。希望您已经找到了这个(或另一个)解决方案,但我想我还是会发布它,以防它能为别人节省一些时间。

myMap 是本例中我的 MapKit View 的 Outlet。

关于ios - 在 Cell 中使用 MKMapView 时内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25408882/

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