阻止 MKMapView 重新加载

发布于 2024-10-04 01:57:06 字数 1270 浏览 0 评论 0 原文

我有一个 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我为君王 2024-10-11 01:57:06

尝试将地图区域/地图范围设置为您想要的,然后更改 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;

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:

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];

And then for the properties try this:

mapView.zoomEnabled = NO;
mapView.userInteractionEnabled = NO;
ˇ宁静的妩媚 2024-10-11 01:57:06

感谢 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 custom UITableViewCell dealloc method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文