Ios 自定义注释未加载到数组中?

Ios 自定义注释未加载到数组中?,ios,annotations,Ios,Annotations,下面是我的代码,用于将自定义注释加载到数组中,然后使用addAnnotations将此数组添加到地图中。我的地图上没有任何图钉。如果我替换[annotations addObject:annotation]带有[annotations addObject:item.placemark]我获得PIN,但它们不是我的自定义批注。我有一个名为Annotation的customAnnotation类。我做错了什么 NSMutableArray *annotations = [NSMutableArray

下面是我的代码,用于将自定义注释加载到数组中,然后使用addAnnotations将此数组添加到地图中。我的地图上没有任何图钉。如果我替换
[annotations addObject:annotation]带有
[annotations addObject:item.placemark]我获得PIN,但它们不是我的自定义批注。我有一个名为Annotation的customAnnotation类。我做错了什么

NSMutableArray *annotations = [NSMutableArray array];

                [response.mapItems enumerateObjectsUsingBlock:^(MKMapItem *item, NSUInteger idx, BOOL *stop) {

                    // if we already have an annotation for this MKMapItem,
                    // just return because you don't have to add it again

                    for (id<MKAnnotation>annotation in mapView.annotations)
                    {
                        if (annotation.coordinate.latitude == item.placemark.coordinate.latitude &&
                            annotation.coordinate.longitude == item.placemark.coordinate.longitude)
                        {
                            return;
                        }

                    }


                    // otherwise add it

                    Annotation *annotation = [[Annotation alloc] initWithPlacemark:item.placemark];
                    annotation.title = mapItem.name;
                    annotation.subtitle = mapItem.placemark.addressDictionary[(NSString *)kABPersonAddressStreetKey];
                    [annotations addObject:annotation];

 [self.mapView addAnnotations:annotations];
NSMutableArray*注释=[NSMutableArray];
[response.mapItems enumerateObjectsUsingBlock:^(MKMapItem*项,整数idx,布尔*停止){
//如果此MKMapItem已有注释,
//只需返回,因为您不必再次添加它
用于(mapView.annotations中的idannotation)
{
if(annotation.coordinate.latitude==item.placemark.coordinate.latitude&&
annotation.coordinate.longitude==item.placemark.coordinate.longitude)
{
返回;
}
}
//否则添加它
Annotation*Annotation=[[Annotation alloc]initWithPlacemark:item.placemark];
annotation.title=mapItem.name;
annotation.subtitle=mapItem.placemark.addressDictionary[(NSString*)KabPersonalAddressStreetKey];
[注释添加对象:注释];
[self.mapView addAnnotations:annotations];

问题很简单,只可能是(a)添加注释的问题;或(b)显示注释的问题。我最初怀疑是前者(考虑到您奇怪的缩进,我怀疑您可能对一些您没有与我们共享的异步调用有问题),但如果您说如果使用placemark而不是注释,效果很好,那么我不得不怀疑问题一定在于注释的显示(即
viewForAnnotation

首先,我建议您做一些诊断工作。您可以通过在调用
addAnnotations
之前和之后记录
self.mapView.annotations
计数来确认注释是否正确添加。我怀疑(根据您所说的),您会看到计数上升


然后我会查看注释的
视图
,并确保它正确地处理了
注释
逻辑,所以可能你有一些问题。根据与我们共享的一小段代码很难说。

感谢你的回答并帮助我分解问题背后的逻辑。嗯。现在我得到了最奇怪的行为。当我进行更改时,我提到它修复了注释问题……但现在当我尝试点击我的后退按钮(解除viewcontroller)我的应用程序崩溃。我获得了EXC\u BAD\u访问权限(代码=2,地址=0x4)@user1639594我确信这很令人沮丧,但我们这里没有足够的信息来诊断发生了什么。我会尝试打开,看看这是否有助于识别出有问题的代码。如果没有,请在代码中设置您自己的断点,然后单步遍历候选例程,看看您是否能够识别出是哪一行导致了问题。如果出现最坏的情况最糟糕的是,请随意上传项目的某个地方,我可以看看。