2

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

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 都使用这种方法来做到这一点 - 但它不工作,有什么建议吗?

以及该操作的代码:

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

1 回答 1

3

您没有为注释设置CalloutAccessoryView

示例代码

    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;
}
于 2013-05-24T12:12:49.450 回答