我创建了一个 MKMapView
的单例类,我在许多类中使用它来打开和关闭 showsUserLocation
和跟踪方法。该代码似乎适用于单例类;但是,它对模拟器中的实际 map 没有影响。我相信 Storyboard
中的 MKMapView
实际上不是 Singleton 类的实例,即使我在 Interface Builder Custom Class 类别中更改了它的类,并创建了一个 IBOutlet
到它。如何确保 Storyboard
中的 map 与我的代码所影响的 map 相同?
最佳答案
class var GsharedInstance: GoogleMap {
struct Static {
static let instance: GoogleMap = GoogleMap()
}
return Static.instance
}
Swift 中的简单方法
关于ios - 如何将 MKMapView 的单例类设置为 Storyboard 中的 map ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27329410/