0

我有一个带有有序对象列表的表格视图,按我和对象之间的距离排序。我需要在地图中显示注释以向用户显示对象的位置,但我需要以与表格顺序相同的顺序显示,因为那时我需要按下一个以显示每个对象的信息。

问题是,当我每次将注释放入地图时,注释的标签号都是不同的。就像地图以随机顺序添加注释一样。

我有一个注释数组,然后将该数组添加到地图中:

    MKPointAnnotation* tallerAnnotation = [[MKPointAnnotation alloc] init];
    [tallerAnnotation setCoordinate:CLLocationCoordinate2DMake([taller getLatitudTaller],       [taller getLongitudTaller])];
    [tallerAnnotation setTitle:[taller getNombre]];
    [tallerAnnotation setSubtitle:[taller getDomicilio]];
    [annotations addObject:tallerAnnotation];

然后将数组添加到地图中:

    [mapa addAnnotations:annotations];

这是我自定义注释的代码:

    - (MKAnnotationView *) mapView: (MKMapView *) mapa viewForAnnotation: (id <MKAnnotation>) annotation_ {

    MKPinAnnotationView *pin = (MKPinAnnotationView *) [self.mapa dequeueReusableAnnotationViewWithIdentifier: @"YourPinId"];
    if (pin == nil) {
    pin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation_ reuseIdentifier: @"YourPinId"];


    }
    else {
    pin.annotation = annotation_;
    }
    if ([[annotation_ title]isEqualToString:@"Tu posición"])
    pin.pinColor = MKPinAnnotationColorRed;
    else
    {
    [pin setCanShowCallout:YES];
    pin.pinColor = MKPinAnnotationColorGreen;
    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [rightButton addTarget:self action:@selector(getInfoTalleres:) forControlEvents:UIControlEventTouchUpInside];
    [rightButton setTag:posicionActualTaller]; 
    pin.rightCalloutAccessoryView = rightButton;

    UILabel *l1=[[UILabel alloc] init];
    l1.frame=CGRectMake(0, 5, 50, 15);
    l1.backgroundColor = [UIColor clearColor];
    l1.textColor = [UIColor whiteColor];
    l1.font=[UIFont fontWithName:@"Arial Rounded MT Bold" size:(10.0)];
    l1.text=[[[mainDelegate getTalleres]objectAtIndex: posicionActualTaller]getDistancia];
    posicionActualTaller +=1;
    UIView *leftCAV = [[UIView alloc] initWithFrame:CGRectMake(0,0,50,15)];
    [leftCAV  addSubview : l1];
    pin.leftCalloutAccessoryView = leftCAV;
    }


    pin.animatesDrop = YES;
    return pin;
    }

我想做这样的事情:

    - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
    {
    NSLog(@"Tag del taller = %i",[control tag]);
    [mainDelegate setTallerActual:[[mainDelegate getTalleres]objectAtIndex:[control tag]]];
    [self detalleTaller];
    }

每次我进入地图视图时,[控制标签]都有不同的值,这样就不可能做类似 [objects objectAtIndex:[control tag]];

请我需要帮助。

提前致谢。

好的,我终于找到了解决方案。

当我创建

UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self action:@selector(getInfoTalleres:) forControlEvents:UIControlEventTouchUpInside];

对于注释,我以这种方式将注释标题分配给按钮:

[rightButton setTitle:[annotation_ subtitle] forState:UIControlStateNormal];

然后:

-(void)getInfoTalleres:(UIButton* )sender
{   
for (int i = 0; i < [[mainDelegate getTalleres]count]; i++)
{
    if ([[sender currentTitle] isEqualToString:[[[mainDelegate getTalleres]objectAtIndex:i]getDomicilio]])
    {
        [mainDelegate setTallerActual:[[mainDelegate getTalleres]objectAtIndex:i]];
        [self detalleTaller];
        break;
    }
}

}

希望有人可以使用这个解决方案。

非常感谢可可。

问候。

4

1 回答 1

0

在此处检查答案它访问标题属性确定选择了哪个 MKPinAnnotationView?和教程http://www.scribd.com/doc/91629556/192/The-MKAnnotationView-class

如果您仍然找不到答案,请告诉我

于 2012-06-14T11:37:16.043 回答