gpt4 book ai didi

ios - MapView 向自定义注释添加一个 Action (向右箭头)

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:09:59 24 4
gpt4 key购买 nike

我通过这个 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];
}

最佳答案

您没有为注释设置 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;
}

关于ios - MapView 向自定义注释添加一个 Action (向右箭头),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16734533/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com