In my ios swift
app I have a UITableViewController
with cells added dynamically. Each cell has a MKMapView
embedded and I'm setting the center of the map for each cell on different coordinates. I'm doing so 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 fine and it works, but I imagine with lots of records there will be problems with memory - even now with only couple cells when user scrolls the table - each map loads instantly and I can only imagine how much compute power it takes to do so.
So my question is - is there a way of changing the dynamic map view to some kind of maybe screenshot of the actual position of the map? Will it work faster when it comes to lots of cells?