I have a MKMapView with scrolling and userInteraction disabled within a UITableViewCell. The desired effect (effectively a static image of the map in a certain position) works really well but when the MKMapView drifts on and off screen (scrolling) it reloads the map, which occasionally causes the app to crash. I have loaded the custom UITableViewCell in like any other UITableViewCell in cellForRowAtIndexPath:
if(indexPath.section == 0 && indexPath.row == 0)
{
MapTableViewCell *cell = (MapTableViewCell *)[tableView dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"%@Map", cellIdentifier]];
if(cell == nil)
{
cell = [[[MapTableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier] autorelease];
}
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"MapTableViewCell" owner:self options:nil];
for(id currentObject in topLevelObjects)
{
if([currentObject isKindOfClass:[UITableViewCell class]])
{
cell = (MapTableViewCell *)currentObject;
break;
}
}
return cell;
}
I’ve found out that with this current method, if you let the map image load before moving the UITableView then it’s OK. But if you move it off the screen before it’s finished loading then it will crash! 🙁
I will just point out that I do not want to be able to control the map in any way or show any annotations on it. I did try to screenshot a map view, hide it from screen and display that screenshot as a UIImageView in the UITableViewCell but this wasn’t fast enough!
EDIT: Updated code. This is the full code for this method. Is my custom TableViewCell alloc incorrect here?
Thanks to tc for the answer (the comment above).
What was required was for me to release the
MKMapViewin the customUITableViewCelldealloc method.