停止重新加载MKMapView [英] Stop MKMapView from reloading

查看:107
本文介绍了停止重新加载MKMapView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MKMapView,其中在UITableViewCell中禁用了滚动和userInteraction.所需的效果(实际上是地图在特定位置的静态图像)效果很好,但是当MKMapView在屏幕上滚动和滚动(滚动)时,它会重新加载地图,这有时会导致应用程序崩溃.我已经像在cellForRowAtIndexPath中的任何其他UITableViewCell中一样加载了自定义UITableViewCell:

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

我发现使用这种当前方法,如果在移动UITableView之前让地图图像加载,就可以了.但是,如果在完成加载之前将其从屏幕上移开,它将崩溃! :(

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! :(

我只是指出,我不希望能够以任何方式控制地图或在地图上显示任何注释.我确实尝试过对地图视图进行屏幕截图,将其从屏幕上隐藏起来,然后在UITableViewCell中以UIImageView的形式显示该屏幕截图,但这还不够快!

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!

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

Updated code. This is the full code for this method. Is my custom TableViewCell alloc incorrect here?

推荐答案

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

Thanks to tc for the answer (the comment above).

我需要在自定义的UITableViewCell dealloc方法中释放MKMapView.

What was required was for me to release the MKMapView in the custom UITableViewCell dealloc method.

这篇关于停止重新加载MKMapView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆