0

I have a MKMapView in one of my static cells. Instead of being able move the map around, I would like the user to be able to tap the map and have it expand full screen. Then within the full screen the user can move around and zoom in and out. They will eventually be able to see where I have pins placed based on other users' city where they are located.

I am getting an error when the map is tapped.

Thread 1: "-[HomeTableViewController triggerTouchAction:]: unrecognized selector sent to instance 0x115e2f8a0"

Here is the important code for the map and touch gesture for the controller:

import UIKit
import CoreLocation
import MapKit

class HomeTableViewController: UITableViewController, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, CLLocationManagerDelegate, MKMapViewDelegate {

@IBOutlet weak var mapView: MKMapView!

override func viewDidLoad() {
    super.viewDidLoad()
    
    // Always adopt a light interface style.
    overrideUserInterfaceStyle = .light
    
    let gestureRecognizer = UITapGestureRecognizer(target: self, action:"triggerTouchAction:")
    mapView.addGestureRecognizer(gestureRecognizer)
    
}

override func numberOfSections(in tableView: UITableView) -> Int {
    // #warning Incomplete implementation, return the number of sections
    return 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete implementation, return the number of rows
    return 7
}

func triggerTouchAction(gestureReconizer: UITapGestureRecognizer) {
      //Add alert to show it works
    print("Map Tapped")
}

}

I would love to be able to move forward with this part of my app. Thank you in advance for helping me out. I am very new to coding and wish I had gotten my degree in it.

NewCoder
  • 35
  • 6
  • The question, in my mind, is whether you should have map view within cell, or a map snapshot. I always use the latter. That eliminates issues related to map views processing touches themselves. See [`MKMapSnapshotter`](https://developer.apple.com/documentation/mapkit/mkmapsnapshotter). – Rob Oct 22 '20 at 00:24
  • @Rob Do you think that would look tacky? I was thinking of doing that and have it acting like a button but I don't know if it would look good. What do you think? – NewCoder Oct 22 '20 at 00:42
  • If the map snapshots convey meaningful information (e.g. they’re big enough to discern relevant info that the user will use to decide which row to tap on), then it can be useful. If it’s merely there to provide some visual interest in the table view cell, then it might be more distracting that useful. It’s hard to say in the abstract. You should do mockups of each and do some user testing. – Rob Oct 22 '20 at 15:25
  • @Rob After looking into everything, I want to use a snapshot of the user's current location to populate the screenshot and then when tap expand fullscreen to am interactive map. I clicked the link you shared and haven't been able to find any tutorials on how I would go about setting this up. I could really use your help. – NewCoder Oct 22 '20 at 21:24
  • Sorry, I've been busy, but posted comment under your [follow-up question](https://stackoverflow.com/questions/64493563/create-a-clickable-map-preview-using-mkmapsnapshotter#comment114040204_64493563), namely “Use MKMapSnapshotter to create an image of a map (e.g. https://stackoverflow.com/a/42773351/1271826). You can then create a button using the resulting image. Or just use it in a `UIImageView`, allow user interaction, and add a [tap] gesture recognizer.” Or, if it was in a table view row, let the table/row handle the tap. – Rob Oct 23 '20 at 05:29

0 Answers0