Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 未添加的MKMapView渲染上下文问题_Iphone_Ios_Objective C_Mkmapview_Rendering - Fatal编程技术网

Iphone 未添加的MKMapView渲染上下文问题

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.

我正在尝试从MKMapView中获取图像,以将其作为缩略图添加到UITableViewCell中。问题是图像渲染为纯色,而不是正确的贴图。我将MKMapView直接添加到我的视图中只是为了测试目的,并且它可以正确加载

以下是CellForRowatineXpath中的一些代码:

//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];
下面是正在发生的事情的图像: