我試圖通過函數func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView)
將數據傳遞給我的第二個VC上的標籤。Swift:Constant''在被初始化之前使用
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
print("Annotation selected")
if let annotation = view.annotation as? POIAnnotations {
let destVC : ShopDetailViewController
destVC.shopName.text = annotation.title!
print("Your annotation title is: \(annotation.title!)")
}
}
當我設置shopName.text
到annotation.title
,我得到一個錯誤,指出:正在初始化之前使用
常量 'destVC'。
我不太確定發生了什麼問題。
不會'讓destVC:ShopDetailViewController'是初始化呢?我還會如何初始化它? – daanyyaal
@daanyyaal如果你不知道如何在故事板中設置viewController的標識符檢查這個答案http://stackoverflow.com/a/15478575/6433023 –