Mike Meyers Mike Meyers - 2 months ago 20
iOS Question

Load MKMapView in UITableViewCell quickly

I'm only a relatively new iPhone programmer so hopefully this makes sense.

I've created a

UITableView
in a
storyboard
and it is displaying correctly. I have created two different types of prototype table view cells. One is just a simple cell displaying text using the "Left Detail" style while the other contains an
MKMapView
and a toolbar. I create a single instance of the map an all the rest of the cells are the simple text cells.

The problem I am having is that when the table view is initially displayed, the
UITableViewCell
containing the map is off-screen. When I scroll down, the UI pauses while the cell is loaded. Based on Instruments, it seems that the time is spent in
[MKMapView initWithCoder]
but I don't know of any way to load the prototype cell before dequeuing it.

Previously the map cell was above-the-fold so was loaded before I did any scrolling. Now that I have rearranged things, it is loading later and causing a delay.

Is there any way that I can pre-load the
UITableViewCell
containing the
MKMapView
, or put some of the loading of the
MKMapView
into the background?

Answer

You can preload the MKMapView view instance before, add it as subview to the cell in the cellForRowAtIndexPath method. That way the map view have some time to load before the cell is displayed.