1

In MapBox, I want when the user touches an annotation pin, that a tableview within a callout will appear. I tried using, but it just ends up covering the entire screen. Is there a better way to achieve this?

func mapView(_ mapView: MGLMapView, leftCalloutAccessoryViewFor annotation: MGLAnnotation) -> UIView? {

    let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
  let vc: UITableViewController = storyboard.instantiateViewController(withIdentifier: "newtableview") as! UITableViewController


    self.present(vc, animated: true, completion: nil)
    return nil
}

For better clarification, this is similar to what I am trying to achieve For better clarification, this is similar to what I am trying to achieve

  • If I understand correctly, your question could be rewritten as: _Is there a way to present a view controller not covering the entire screen?_ Yes, you can, use a child view controllers, see [this](http://stackoverflow.com/a/17795162/1305067). – paulvs Dec 21 '16 at 22:12

1 Answers1

1

This is happening because you are pushing a new vc onto the navigation stack. The previous vc that has your map is now on the previous page. To achieve that functionality you will have to create a callout by scratch. The following will give you maximum customization control:

  1. Subclass MKAnnotation. This should include all the data you will need for the customized callout

  2. Subclass UIView. This view will contain your tableview. It should accept the data from step 1.

  3. Use mapView:didSelect delegate method. When the user selects an annotation this method is called and you are passed an MKAnnotationView that has a MKAnnotation as the property. Cast it as your subclass and you should have all the data necessary for the callout

  4. Add the callout manually. Create a new instance of the UIView from step 2. You can access the data from the MKAnnotation subclass from step 1 explained in step 3. Add this view as a subview to the map.

  5. Layout callout. Either set the frame manually or use autolayout. You can get the position of the selected annotation by the MKAnnotationView's frame.

Good luck!!!

Andrew McKinley
  • 1,137
  • 1
  • 6
  • 11