代码之家  ›  专栏  ›  技术社区  ›  ingh.am

停止重新加载MKMapView

  •  1
  • ingh.am  · 技术社区  · 14 年前

    我有一个 MKMapView 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 回复  |  直到 14 年前
        1
  •  1
  •   Matt    14 年前

    尝试将映射的区域/映射的范围设置为所需的值,然后更改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;
    
        2
  •  1
  •   ingh.am    14 年前

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

    我需要的是释放 MKMapView 在习俗中 UITableViewCell