我通过以下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"]);
}
我正在尝试做的是在注释的标题/描述的右侧添加详细信息显示按钮,但是这并没有添加按钮,我为此找到的所有tut都使用此方法进行了操作-但是它不起作用,有什么建议吗?
以及该操作的代码:
-(void)btnClicked:(id)sender{
UIAlertView *btnAlert = [[UIAlertView alloc] initWithTitle:@"title" message:@"msg" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:nil, nil];
[btnAlert show];
}
最佳答案
您没有为注释设置标注附件视图。 示例代码
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将操作添加到自定义注释(向右箭头),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16734533/