Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone MKMapView中的MKAnnotation随机顺序_Iphone_Objective C_Mkmapview_Mkannotation - Fatal编程技术网

Iphone MKMapView中的MKAnnotation随机顺序

Iphone MKMapView中的MKAnnotation随机顺序,iphone,objective-c,mkmapview,mkannotation,Iphone,Objective C,Mkmapview,Mkannotation,我有一个带有有序对象列表的表视图,按我和对象之间的距离排序。我需要在地图中显示注释,以便向用户显示对象的位置,但我需要以与表的顺序相同的顺序显示,因为我需要使用一个按钮来显示每个对象的信息 问题是,每次在地图中放置注释时,注释的标记号都不同。就像地图以随机顺序添加注释一样 我有一个注释数组,然后将该数组添加到地图中: MKPointAnnotation* tallerAnnotation = [[MKPointAnnotation alloc] init]; [tallerAnn

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

问题是,每次在地图中放置注释时,注释的标记号都不同。就像地图以随机顺序添加注释一样

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

    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];
然后将数组添加到地图:

    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;
    }
每次我进入地图视图时,[control tag]都有不同的值,这样就不可能执行类似于[objects objectAtIndex:[control tag]]的操作

求你了,我需要帮助

提前谢谢

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

当我创建

UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self action:@selector(getInfoTalleres:) forControlEvents:UIControlEventTouchUpInside];
对于注释,我通过以下方式将注释标题指定给按钮:

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

-(void)GetInfoTallers:(UIButton*)发送方
{   
for(int i=0;i<[[main delegate gettallers]计数];i++)
{
if([[sender currentTitle]isEqualToString:[[mainDelegate GetTallers]objectAtIndex:i]getDomicilio]]
{
[mainDelegate setTallerActual:[[mainDelegate GetTallers]对象索引:i]];
[自我毁灭];
打破
}
}
}

希望有人能使用这个解决方案

非常感谢


注意。

在此处检查答案,它将访问标题属性和教程


如果您仍然找不到答案,请告诉我,我仍然无法理解您的问题:(请在我这样做时解释:-(无效)地图视图:(MKMapView*)地图视图注释视图:(MKAnnotationView*)视图调用访问控制点击:(UIControl*)控件{NSLog(@“Tag del Tager=%i),[control Tag]);[Main委托设置实际:[[mainDelegate getTalleres]objectAtIndex:[control tag]];[self-DeTaller];}[sender tag]在每次我进入地图视图时都有一个不同的值,这样就不可能像[objects objectAtIndex:[sender tag]];你可以访问callOutAccesory中的标题或副标题。有了标题,你就可以得到你的对象。[控制标题]对我来说不起作用,我只能得到控件的标签,这是因为我需要控件的标签一直是相同的,并且不会每次进入MapViewHi Cocoa时都改变。我已经阅读了链接,如果我只有一个或两个注释,这可能是一个解决方案。问题是我不知道有多少注释因为我从数据库接收对象,所以我认为应该这样做:if([view.annotation.title isEqualToString:@“Golden Gate”]){//在新的viewcontroller中加载Golden Gate信息}对我来说没什么用,不过还是要谢谢!!如果你得到了当前标题,你可以在for循环中与你的数组进行比较,然后你就可以轻松地与for的所有数组进行比较(int i=0;i