我想在UITableView的最后一个单元格中显示MKMapView。
我在UITableViewCell中有一个MKMapView当我滚动UITableViewCell时,它会刷新MKMapView。并且它与错误崩溃:必须在主线程上初始化MKMapView。
滚动UITableView的滚动视图时,如何防止MKMapView重新加载?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.view endEditing:YES];
if (indexPath.row !=[arrExit count]) //If it is not last cell
{
static NSString *CellIdentifier = @"BTSTicketsCellIdentifier";
BTSComparePricesCell *cell = (BTSComparePricesCell *)[tblComparePrices dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"BTSComparePricesCell" owner:self options:nil];
for (id oneObject in nib) if ([oneObject isKindOfClass:[BTSComparePricesCell class]])
cell = (BTSComparePricesCell *)oneObject;
}
if (!isDragging_msg && !isDecliring_msg)
{
[dicImages_msg setObject:[UIImage imageNamed:@"rowDefault.png"] forKey:[[arrExit objectAtIndex:indexPath.row] valueForKey:@"Merchant_Logo"]];
[self performSelectorInBackground:@selector(downloadImage_3:) withObject:indexPath];
}
return cell;
}
else{ //If it is a last cell
static NSString *CellIdentifier = @"BTSTicketsCell";
BTSMapViewCell *cell = (BTSMapViewCell *)[tblComparePrices dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"BTSMapViewCell" owner:self options:nil];
for (id oneObject in nib) if ([oneObject isKindOfClass:[BTSMapViewCell class]])
cell = (BTSMapViewCell *)oneObject;
}
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:[flux objectForKey:@"Venue"]
completionHandler:^(NSArray* placemarks, NSError* error)
{
if (placemarks && placemarks.count > 0)
{
CLPlacemark *topResult = [placemarks objectAtIndex:0];
MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:topResult];
[cell.MapVw addAnnotation:placemark];
CLLocationCoordinate2D _venue = placemark.coordinate;
[cell.MapVw setCenterCoordinate:_venue];
MKCoordinateRegion region = cell.MapVw.region;
region.span.longitudeDelta = 1.0;
region.span.latitudeDelta = 1.0;
[cell.MapVw setRegion:region animated:YES];
}
}
];
return cell;
}
}
提前致谢。
答案 0 :(得分:1)
试试这个,希望它能奏效 在View Controller中创建一个带有强引用的MKMapView实例,您可以在表视图中加载地图。将lat long值分配给该地图视图实例。在CellforRowAtIndexpath上设置cell.MapVw = mapViewInstance。