2016-10-09 1 views
-1

Явно новичок в iOS dev, и я следую «первым шагам с помощью iOS MapBox SDK» для Swift (https://www.mapbox.com/help/first-steps-ios-sdk/). Все было хорошо с отображением карты, пользовательским стилем и добавлением аннотации. Но затем возникла проблема при попытке взаимодействия с аннотацией для отображения ее названия и субтитров.аннотация iOS Mapbox не открывается

print("allow")print("tap on callout"), кажется, никогда не вызываются. Даже mapView.selectAnnotation(point, animated: true) ничего не делает (и это не было ничего делать без нее тоже)

Использования Xcode 8.0, MacOS Sierra, Swift 3 прошивки 10

Я немного невежественной сейчас, любой совет будет следует понимать

Спасибо заранее

ViewController.swift:

import UIKit 
import Mapbox 
class ViewController: UIViewController{ 

    @IBOutlet var mapView: MGLMapView! 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     // Do any additional setup after loading the view, typically from a nib. 
     let point = MGLPointAnnotation() 
     point.coordinate = CLLocationCoordinate2D(latitude: 46.082666, longitude:7.508510) 
     point.title = "Title" 
     point.subtitle = "Subtitle" 
     mapView.addAnnotation(point) 
     mapView.selectAnnotation(point, animated: true) 
     print("add annotation"); 

    } 

    // Return `nil` here to use the default marker. 
    func mapView(mapView: MGLMapView, viewForAnnotation annotation: MGLPointAnnotation) -> MGLAnnotationView? { 
     print("default marker") 
     return nil 
    } 

    // Allow callout view to appear when an annotation is tapped. 
    func mapView(mapView: MGLMapView, annotationCanShowCallout annotation: MGLPointAnnotation) -> Bool { 
     print("allow") 
     return true 
    } 
    func mapView(mapView: MGLMapView, tapOnCalloutForAnnotation annotation: MGLAnnotation) { 
     print("tap on callout") 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 


} 

Screenshot: Annotation displays where it's supposed to but cannot be interacted with

+0

установлен ли MAPview делегат вверх? – Sealos

+0

Есть ли у вас такая же настройка, как https://www.mapbox.com/help/first-steps-ios-sdk/#ib-set-delegate – Spitfire4466

+0

Твои метки уже указывают на то, что вы используете Swift. Нет необходимости добавлять это в заголовок. –

ответ

0

Где этот код утверждает

class ViewController: UIViewController{ 

Он не был настроен, чтобы быть делегатом карты. Эта линия должна быть

class ViewController: UIViewController, MGLMapViewDelegate { 

Как указано в документе first steps guide.

+0

Ах спасибо! Plus функции должны были быть приспособлены вместо 'MGLPointAnnotation' он должен быть' MGLAnnotation' в: 'Func MAPview (_ MAPview: MGLMapView, viewFor: MGLAnnotation) -> MGLAnnotationView { возврат ноль }' – Spitfire4466

0

Помимо добавления MGLMapViewDelegate в класс, как указано в ответе tmcw, вы также должны добавить следующую строку в ваш метод viewDidLoad():

mapView.delegate = self 
Смежные вопросы