MKAnnotationView viewForAnnotation从未调用 [英] MKAnnotationView viewForAnnotation never called
问题描述
无论如何,我似乎删除或错过了重要的部分。似乎MapViewController和以下代码之间没有连接
- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation :(id< MKAnnotation>)注释
{
NSLog(@MKAnnotationView);
return nil;
}
设置注释看起来像这样,它的效果很好:
- (void)createPoi:(CLLocationCoordinate2D)theCoordinate
{
NSLog(@createPoi);
RandomAnnotation * randomAnnotation = [[RandomAnnotation alloc] init];
[randomAnnotation setTheCoordinate:theCoordinate];
[randomAnnotation setTheTitle:@bla];
[randomAnnotation setTheSubTitle:@bla];
[self.mapAnnotations insertObject:randomAnnotation atIndex:kRandomAnnotationIndex];
[randomAnnotation release];
[self.mapView addAnnotation:[self.mapAnnotations objectAtIndex:kRandomAnnotationIndex]];
}
我不知道出了什么问题。有人可以给我一个提示什么是什么吗?我不得不承认,我没有任何代表模式的经验。
确保地图视图的委托
属性设置。
如果地图在IB中创建,请右键单击并将其代理插座文件的所有者。
如果地图是以代码创建的,则在创建地图视图后设置委托:
mapView.delegate = self;
after i spend 2 days of searching the bug i have to ask for help here. i do have MapViewController and place some pins on the map. i´ve copied most of the code from MapCallouts and WeatherMap of the apple code samples.
anyhow it seems that i´ve deleted or missed essential parts. it seems there is no connection between the MapViewController and the following code
- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
NSLog(@"MKAnnotationView");
return nil;
}
setting an annotation looks like this and it works well:
- (void)createPoi:(CLLocationCoordinate2D)theCoordinate
{
NSLog(@"createPoi");
RandomAnnotation *randomAnnotation = [[RandomAnnotation alloc] init];
[randomAnnotation setTheCoordinate:theCoordinate];
[randomAnnotation setTheTitle:@"bla"];
[randomAnnotation setTheSubTitle:@"bla"];
[self.mapAnnotations insertObject:randomAnnotation atIndex:kRandomAnnotationIndex];
[randomAnnotation release];
[self.mapView addAnnotation:[self.mapAnnotations objectAtIndex:kRandomAnnotationIndex]];
}
i can´t figure out what's wrong. could anybody give me a hint what´s missing? i have to admit that i don´t have any experience with the delegate pattern.
Make sure the map view's delegate
property is set.
If the map is created in IB, right-click on it and hook up its delegate outlet to File's Owner.
If the map is created in code, set the delegate after creating the map view:
mapView.delegate = self;
这篇关于MKAnnotationView viewForAnnotation从未调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!