[weak self]
。我遇到的问题是,代码从未执行过我的语句:
guard
当设置我的func zoomInButton() -> CPMapButton {
let zoomInButton = CPMapButton { [weak self] button in
// Code never continues past here.
guard let self = self else { return }
if let mapView = self.mapViewController?.mapView {
mapView.setZoomLevel(mapView.zoomLevel + 1, animated: true)
}
}
let bundle = Bundle.main
zoomInButton.image = UIImage(named: "carplay_plus", in: bundle, compatibleWith: self.traitCollection)
return zoomInButton
}
。
CPMapTemplate
没有人会看到为什么它不会继续过去的原因?我已经查看了其他代码示例,这看起来正确。
我弄清楚了。我打电话给我的班级,但从未有过强有力的提及,因此上面的代码不起作用。我创建了一个共享对象,并解决了问题。