停止MKMapView重新加载

时间:2010-11-24 00:01:04

标签: iphone uitableview mkmapview tablecell

我在MKMapView内禁用了滚动和userInteraction UITableViewCell。期望的效果(实际上是某个位置的地图的静态图像)非常有效,但当MKMapView在屏幕上移动(滚动)时,它会重新加载地图,这偶尔会导致应用程序崩溃。我已加载自定义UITableViewCell,与UITableViewCell中的任何其他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;
}

我发现使用这种当前方法,如果你在移动UITableView之前加载地图图像,那么就可以了。但如果你在完成加载之前将它移出屏幕,它就会崩溃! :(

我只想指出,我不想以任何方式控制地图或在其上显示任何注释。我确实试图截取地图视图,将其隐藏在屏幕上并在UIImageView中将该屏幕截图显示为UITableViewCell,但这还不够快!

编辑:更新了代码。这是此方法的完整代码。我的自定义TableViewCell分配不正确吗?

2 个答案:

答案 0 :(得分:1)

尝试将地图区域/地图范围设置为您想要的内容,然后更改userInteractionEnabled和zoomEnabled的属性。所以可能是这样的:

MKCoordinateRegion region;
region.center = "location";  //a CLLocationCoordinate2D location of where ever

MKCoordinateSpan span;
span.latitudeDelta = 0.03; //desired size for both latDelta and lonDelta
span.longitudeDelta = 0.03;
region.span = span;

[mapView setRegion:region animated:YES];

然后对于属性试试这个:

mapView.zoomEnabled = NO;
mapView.userInteractionEnabled = NO;

答案 1 :(得分:1)

感谢tc的答案(上面的评论)。

我需要在自定义MKMapView dealloc方法中发布UITableViewCell

相关问题