Swift MKAnotation-无法将类型x的值分配给类型MKAnnotation
我有一张带有注释的地图,效果很好。我想要一个segmentedcontrol来更改注释 此代码Swift MKAnotation-无法将类型x的值分配给类型MKAnnotation,swift,xcode,mkannotation,Swift,Xcode,Mkannotation,我有一张带有注释的地图,效果很好。我想要一个segmentedcontrol来更改注释 此代码 annotations = getMapAnnotations() // Add mappoints to Map mapInfView.addAnnotations(annotations ) 在ViewDidLoad中工作,但在更改plist文件以从中获取数据后,我尝试实现它。 我不明白为什么get不能将类型为['Stands']的值赋给tupe MKAnnotation?当它在分段控制代码中而
annotations = getMapAnnotations()
// Add mappoints to Map
mapInfView.addAnnotations(annotations )
在ViewDidLoad中工作,但在更改plist文件以从中获取数据后,我尝试实现它。
我不明白为什么get不能将类型为['Stands']的值赋给tupe MKAnnotation?当它在分段控制代码中而不是在viewdidload中时。
有没有更好的方法来更改注释
getannotations()
}
看台阶级
import Foundation
import MapKit
class Stands: NSObject, MKAnnotation {
var title: String?
var subtitle: String?
var no: Int?
var latitude: Double
var longitude:Double
var coordinate: CLLocationCoordinate2D {
return CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
}
init(latitude: Double, longitude: Double) {
self.latitude = latitude
self.longitude = longitude
}
}
IBAction代码
@IBAction func annotType(_ sender: Any) {
let infoChoice = AnnotType(rawValue: infoSegmentController.selectedSegmentIndex)
switch (infoChoice!) {
case .WC:
iFile = "wc"
case .Restaurant:
iFile = "restaurant"
case .ATM:
iFile = "atm"
case .Museums:
print("Museums")
iFile = "museums"
}
print("END")
annotations = getMapAnnotations()
// Add mappoints to Map
mapInfView.addAnnotations(annotations )
}马特是对的。
在视图中,我有多少负载
var annotations = getMapAnnotations()
在@IBAction func annotType()中
我有
annotations = getMapAnnotations()
添加var以再次声明它解决了这个问题
就在类声明之后,还有许多其他变量声明
var annotations:MKAnnotations?
那似乎毫无用处。我刚刚把它注释掉了,应用程序运行良好。什么是注释
?您分配给它,但它在哪里/如何声明?您必须在某个地方有一个var注释
;给我看看另外,显示您的整个viewDidLoad
,您可以在其中声明此功能。我打赌这不一样。
var annotations:MKAnnotations?