In my ios swift app, I have a UITableViewController with adding cells dynamically. Each cell has an integrated MKMapView , and I set the center of the map for each cell in different coordinates. I do this by calling this method:
func centerMapOnLocation(location: CLLocation, map: MKMapView, radius: CLLocationDistance) { let coordinateRegion = MKCoordinateRegionMakeWithDistance(location.coordinate, radius * 2.0, radius * 2.0) map.setRegion(coordinateRegion, animated: true) }
inside cellForRowAtIndexPath :
override func tableView(tview: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tview.dequeueReusableCellWithIdentifier("cell") as! SingleCall let user:SingleUser = self.items[indexPath.row] as! SingleUser let regionRadius: CLLocationDistance = 150 let initialLocation = CLLocation(latitude: user.coordinate.latitude, longitude: user.coordinate.longitude) centerMapOnLocation(initialLocation, map: cell.eventMap, radius: regionRadius) cell.eventMap.zoomEnabled = false cell.eventMap.scrollEnabled = false cell.eventMap.userInteractionEnabled = false }
This is good, and it works, but I believe that with a lot of records there will be memory problems - even now with only couple cells, when the user scrolls the table - each card loads instantly, and I can only imagine how much its power is calculated this is.
So, my question is: is there a way to change the dynamic view of the map to some kind, maybe a screenshot of the actual position of the map? Will it work faster when it comes to many cells?
source share