删除 MKAnnotations 然后将其添加到 MapView 后,我会得到一个空白的 MapView
此问题的后续内容:
强制重新加载视图从实用程序应用程序的 FlipSideView 返回时
从翻转视图返回时,我调用
NSArray *annotations = [NSArray arrayWithArray:[mapView annotations]];
[mapView removeAnnotations:annotations];
“从地图上删除所有图钉”(如果这不是执行此操作的最佳方法,请告诉我)。
然后:
for(Hole *hole in fetchedObjects)
{
double latitude = [hole.Latitude doubleValue];
cord.latitude = latitude;
double longitude = [hole.Longitude doubleValue];
cord.longitude = longitude;
WellPlaceMark *placemark = [[WellPlaceMark alloc] initWithCoordinate:cord withWellType:[NSString stringWithString: hole.WellType]];
[mapView addAnnotation:placemark];
}
另外:
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
if([annotation isKindOfClass:[WellPlaceMark class]])
{
...
}
annView.animatesDrop=FALSE;
return annView;
}
所有这些代码似乎都是在调试器中调用的,但是当它完成时,我会看到一张空白的地图。我尝试缩小,但图钉无处可去。地图在第一次尝试时加载得很好,但是一旦我调用 removeAnnotations
,它们就再也不会返回。
A followup to this quesiton:
Forcing Reload of View when returning from FlipSideView of Utility Application
When returning from the flipside view, I'm calling
NSArray *annotations = [NSArray arrayWithArray:[mapView annotations]];
[mapView removeAnnotations:annotations];
To remove all the pins from the map (let me know if this isn't the best way to do this).
Then:
for(Hole *hole in fetchedObjects)
{
double latitude = [hole.Latitude doubleValue];
cord.latitude = latitude;
double longitude = [hole.Longitude doubleValue];
cord.longitude = longitude;
WellPlaceMark *placemark = [[WellPlaceMark alloc] initWithCoordinate:cord withWellType:[NSString stringWithString: hole.WellType]];
[mapView addAnnotation:placemark];
}
Plus:
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
if([annotation isKindOfClass:[WellPlaceMark class]])
{
...
}
annView.animatesDrop=FALSE;
return annView;
}
All of this code seems to be called in the debugger, but when it's finished, I'm presented with a blank map. I've tried zooming out and the pins are nowhere. The map loads up fine on the first try, but once I call removeAnnotations
, they never return.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现:我在索引 0 处添加了一个新的
MKMapView
,它出现在我已清除的MKMapView
下面。重新使用相同的 MKMapView 解决了问题。I figured it out: I was adding a new
MKMapView
at index 0, which was appearing underneath theMKMapView
I had cleared. Re-using the sameMKMapView
solved the problem.