MapView向自定义注释添加操作(右箭头) [英] MapView add an action to custom annotation (the right arrow)

查看:93
本文介绍了MapView向自定义注释添加操作(右箭头)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过这个for循环创建注释引脚:

I create the annotation pins via this for loop:

UIButton *eventMore = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

for (i = 0; i < [results count]; i++) {
    //NSLog(@"Result: %i = %@", i, results[i]);
    //NSLog(@"%@",[[results objectAtIndex:i] objectForKey:@"long"]);

    myAnn = [[CustomAnnotation alloc] init];
    location.latitude = (double)[[[results objectAtIndex:i] objectForKey:@"lat"] doubleValue];
    location.longitude = (double)[[[results objectAtIndex:i] objectForKey:@"long"] doubleValue];
    myAnn.coordinate = location;
    myAnn.title = [[results objectAtIndex:i] objectForKey:@"title"];
    myAnn.subtitle = [[results objectAtIndex:i] objectForKey:@"strap"];
    [eventMore addTarget:myAnn action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [locations addObject:myAnn];

    //NSLog(@"%i", [[results objectAtIndex:i] objectForKey:@"lat"]);
}

我想要做的是将详细信息按钮添加到对标注的标题/描述的权利,但这不添加一个,所有的tuts我发现为此使用这种方法 - 但它不工作,任何建议?

What I am trying to do with this is add the detail disclosure button to the right of the title/description on the annotation however this does not add one in, and all the tuts I have found for this do it using this method - but it isnt working, any advice?

操作代码:

-(void)btnClicked:(id)sender{
    UIAlertView *btnAlert = [[UIAlertView alloc] initWithTitle:@"title" message:@"msg" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:nil, nil];
    [btnAlert show];
}


推荐答案

strong> CalloutAccessoryView 。

You are not setting the CalloutAccessoryView for your annotation.

示例代码

Sample code

    for (i = 0; i < [results count]; i++) {

    MKPointAnnotation  *myAnn = [[MKPointAnnotation alloc] init];
    location.latitude = (double)[[[results objectAtIndex:i] objectForKey:@"lat"] doubleValue];
    location.longitude = (double)[[[results objectAtIndex:i] objectForKey:@"long"] doubleValue];
    myAnn.coordinate = location;
    myAnn.title = [[results objectAtIndex:i] objectForKey:@"title"];
    myAnn.subtitle = [[results objectAtIndex:i] objectForKey:@"strap"];
    [locations addObject:myAnn];

   }


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

   static NSString *s = @"ann";
   MKAnnotationView *pin = [mapView dequeueReusableAnnotationViewWithIdentifier:s];
   if (!pin) {
    pin = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:s];
    pin.canShowCallout = YES;
    pin.image = [UIImage imageNamed:@"pin.png"];

    pin.calloutOffset = CGPointMake(0, 0);
    UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [button addTarget:self
               action:@selector(viewDetails) forControlEvents:UIControlEventTouchUpInside];
    pin.rightCalloutAccessoryView = button;

}
return pin;
}

这篇关于MapView向自定义注释添加操作(右箭头)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆