我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 分配在这里不正确吗?