gpt4 book ai didi

iphone - UITablViewCell 上的 MKMapView 崩溃

转载 作者:行者123 更新时间:2023-11-29 03:37:32 26 4
gpt4 key购买 nike

我想在 UITableView 的最后一个单元格中显示 MKMapView。

我在 UITableViewCell 中有一个 MKMapView 当我滚动 UITableViewCell 时,它会刷新 MKMapView。并且它因 ERROR: MKMapView must be initialized on the main thread 而崩溃。

当我滚动 UITableView 的 ScrollView 时,我应该怎么做才能防止 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;
}

}

提前致谢。

最佳答案

试试这个,希望能成功 在您要在 TableView 中加载 map 的 View Controller 中创建一个具有强引用的 MKMapView 实例。将经纬度值分配给该 map View 实例。在 CellforRowAtIndexpath 上设置 cell.MapVw = mapViewInstance。

关于iphone - UITablViewCell 上的 MKMapView 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18957219/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com