1

MKMapViewUITableViewCell. 想要的效果(实际上是地图在某个位置的静态图像)效果非常好,但是当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那么就可以了。但是如果你在它完成加载之前把它从屏幕上移开,它就会崩溃!:(

我只想指出,我不希望能够以任何方式控制地图或在其上显示任何注释。我确实尝试过截取地图视图,将其从屏幕上隐藏起来,并将截屏显示为UIImageViewUITableViewCell但这还不够快!

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

4

2 回答 2

1

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

我需要的是MKMapView在自定义UITableViewCelldealloc 方法中释放 。

于 2010-11-30T11:10:10.570 回答
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;
于 2010-11-24T02:24:30.807 回答