0
이름, 설명 및 좌표 개체가있는 영역 개체가 있습니다. mapView
이로드되면 Realm 오브젝트의 각 인스턴스에 대해 핀이 작성됩니다. 내가 원하는 것은 각 핀의 주석을 클릭 할 때 상세 정보보기로 와서 장소에 대한 자세한 정보를 제공한다는 것입니다. 이 Place 객체를 사용자 정의 주석에 전달하여 prepareForSegue
함수의 속성을 사용하고 액세스하여 조작 할 수 있습니까? DetailViewController
?개체를 사용자 지정 주석보기에 전달
여기 내 CustomAnnotation
클래스의 : 여기에 ViewController
의 기능
import Foundation
import UIKit
import MapKit
import RealmSwift
class CustomAnnotation: MKPointAnnotation {
var place = Place()
}
그리고 mapView
:
func loadLocations() {
for place in realm.objects(Place) {
let userLocationCoordinates = CLLocationCoordinate2DMake(place.latitude, place.longitude)
let pinForUserLocation = CustomAnnotation()
pinForUserLocation.coordinate = userLocationCoordinates
pinForUserLocation.title = place.name
pinForUserLocation.subtitle = place.placeDescription
pinForUserLocation.place = place
mapView.addAnnotation(pinForUserLocation)
mapView.showAnnotations([pinForUserLocation], animated: true)
}
}
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if !(annotation is CustomAnnotation) {
return nil
}
let reuseId = "customAnnotation"
var view = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
if view == nil {
view = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
view!.image = UIImage(named:"locationAnnotation")
view!.leftCalloutAccessoryView = UIButton(type: UIButtonType.DetailDisclosure)
view!.canShowCallout = true
}
else {
view!.annotation = annotation
}
return view
}
func mapView(mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
performSegueWithIdentifier("showPlaceDetailSegue", sender: annotation)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showPlaceDetailSegue" {
let vc = segue.destinationViewController as! PlaceDetailViewController
vc.name = sender!.title
vc.descriptionText = sender!.subtitle
vc.coordinate = sender!.coordinate
vc.place = sender!.place
}
}
나에게 "인수 통과 view = CustomAnnotationView (annotation, reuseIdentifier : reuseId)'로 변경하면 아무런 인자도 필요하지 않습니다. 내 CustomAnnotation 클래스에 여전히 오류가있는 것 같습니까? – Luk579
죄송합니다 ... 편집을보고 그 것을 시도하십시오 ... – tbilopavlovic
엄청나게 필요한 것! 감사! – Luk579