我有一个 MKMapView
,在 UITableViewCell
中禁用了滚动和 userInteraction。所需的效果(实际上是某个位置的地图的静态图像)效果非常好,但是当 MKMapView 漂移在屏幕上和屏幕外(滚动)时,它会重新加载地图,这有时会导致应用程序崩溃。我已经像 cellForRowAtIndexPath
中的任何其他 UITableViewCell
一样加载了自定义 UITableViewCell
:
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;
}
我发现使用当前的方法,如果您让在移动 UITableView
之前加载地图图像就可以了。但如果你在加载完成之前将其移出屏幕,那么它就会崩溃! :(
我只想指出,我不想以任何方式控制地图或在其上显示任何注释。我确实尝试对地图视图进行屏幕截图,将其从屏幕上隐藏并将该屏幕截图显示为 UITableViewCell
中的 >UIImageView 但这不够快!
编辑:这是此方法的完整代码。
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?
发布评论
评论(2)
尝试将地图区域/地图范围设置为您想要的,然后更改 userInteractionEnabled 和 ZoomEnabled 的属性。所以可能是这样的:
然后对于属性尝试这样:
Try setting the region of the map/the scope of the map to what you are desiring and then change the properties of userInteractionEnabled and zoomEnabled. So probably something like this:
And then for the properties try this:
感谢 tc 的回答(上面的评论)。
我需要的是在自定义
UITableViewCell
dealloc 方法中释放MKMapView
。Thanks to tc for the answer (the comment above).
What was required was for me to release the
MKMapView
in the customUITableViewCell
dealloc method.