Iphone 未添加的MKMapView渲染上下文问题
我正在尝试从MKMapView中获取图像,以将其作为缩略图添加到UITableViewCell中。问题是图像渲染为纯色,而不是正确的贴图。我将MKMapView直接添加到我的视图中只是为了测试目的,并且它可以正确加载 以下是CellForRowatineXpath中的一些代码:Iphone 未添加的MKMapView渲染上下文问题,iphone,ios,objective-c,mkmapview,rendering,Iphone,Ios,Objective C,Mkmapview,Rendering,我正在尝试从MKMapView中获取图像,以将其作为缩略图添加到UITableViewCell中。问题是图像渲染为纯色,而不是正确的贴图。我将MKMapView直接添加到我的视图中只是为了测试目的,并且它可以正确加载 以下是CellForRowatineXpath中的一些代码: //create correct map thumbnail MKMapView *mapForThumbnail = [[MKMapView alloc] init]; mapForThumbnail.
//create correct map thumbnail
MKMapView *mapForThumbnail = [[MKMapView alloc] init];
mapForThumbnail.frame = CGRectMake(0, 0, 100, 100);
mapForThumbnail.delegate = self;
CLLocationCoordinate2D coords[coordinates.count];
for(int i = 0; i < coordinates.count; i++){
CLLocation *currentLocationCoords = [coordinates objectAtIndex:i];
coords[i] = CLLocationCoordinate2DMake(currentLocationCoords.coordinate.latitude, currentLocationCoords.coordinate.longitude);
}//end for
MKPolyline *polylineForMapThumbnail = [MKPolyline polylineWithCoordinates:coords count:coordinates.count];
[mapForThumbnail addOverlay:polylineForMapThumbnail];
[mapForThumbnail setRegion:MKCoordinateRegionForMapRect([polylineForMapThumbnail boundingMapRect])];
UIGraphicsBeginImageContextWithOptions(CGSizeMake(100, 100), NO, 0.0);
CGContextRef currentContext = UIGraphicsGetCurrentContext();
[mapForThumbnail.layer renderInContext:currentContext];
UIImage *mapImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
cell.imageView.image = mapImage;
cell.detailTextLabel.text = stringForDetailLabel;
cell.detailTextLabel.font = [UIFont fontWithName:@"Verdana" size:12.0f];
cell.detailTextLabel.textColor = [UIColor darkGrayColor];
下面是正在发生的事情的图像: