本文介绍了将id传递给calloutAccessoryControlTapped的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当选中附件按钮时,我需要传递itemId,这样我就可以识别要传递给我的详细视图的项目。
When tabbing the accessory button, i need to pass the itemId, so i can identify the item to pass on to my detail view.
到目前为止:
添加注释:
for (id row in self.detailItem) {
Item *i = (Item *) row;
CLLocationCoordinate2D destination;
destination.latitude = (double) i.latitude;
destination.longitude = (double) i.longitude;
//i.itemid
MapViewAnnotation *destinationAnnotation = [[MapViewAnnotation alloc] initWithTitle: i.name andCoordinate: destination];
[self.mapView addAnnotation: destinationAnnotation];
[destinationAnnotation release];
}
添加配件按钮
- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinAnnotation = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = @"myPin";
pinAnnotation = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinAnnotation == nil )
pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinAnnotation.canShowCallout = YES;
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinAnnotation.rightCalloutAccessoryView = infoButton;
}
return pinAnnotation;
}
找到要传递给详细视图的项目
find the item to pass to detail view
-(void)mapView:(MKMapView *)mapView annotationView:(MKPinAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
// get annotation details here.
NSLog(@"%@", control);
}
推荐答案
添加 itemid
属性为 MapViewAnnotation
类。
添加注释时,请设置调用之前的属性 addAnnotation
:
When adding the annotation, set the property before calling addAnnotation
:
destinationAnnotation.itemid = i.itemid;
[self.mapView addAnnotation: ...
在中calloutAccessoryControlTapped
,访问注释详细信息如下:
In calloutAccessoryControlTapped
, access the annotation details like this:
MapViewAnnotation *annotationTapped = (MapViewAnnotation *)view.annotation;
NSLog(@"annotationTapped.itemid = %@", annotationTapped.itemid);
(如果 itemid
将是 int
,将NSLog中的%@
更改为%d
。 )
(If itemid
will be an int
, change the %@
in the NSLog to %d
.)
这篇关于将id传递给calloutAccessoryControlTapped的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!