5
如何找出被點擊的引腳的引腳ID(即引腳標題和副標題的詳細信息)?如何在地圖註記視圖中找到pin ID?
我有這顯示引腳註釋。此代碼是針對沒有負載:
[resultCoordinate addObjectsFromArray:[sqlClass return_Coordinate]];
if ([resultCoordinate count])
{
for (int i =0; i < [resultCoordinate count]; i++)
{
dict = [resultCoordinate objectAtIndex:i];
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = [[dict objectForKey:@"Lati"] floatValue];
region.center.longitude = [[dict objectForKey:@"Longi"] floatValue];
region.span.longitudeDelta = 0.2f;
region.span.latitudeDelta = 0.2f;
NSString *fishName = [dict objectForKey:@"Fish"];
fishName = [fishName stringByAppendingString:@" "];
NSString *fishWeight = [dict objectForKey:@"Weight"];
fishWeight = [fishWeight stringByAppendingString:@" kg"];
fishName = [fishName stringByAppendingString:fishWeight];
MapAnnotation *ann = [[MapAnnotation alloc] init];
ann.title = fishName;
ann.subtitle = [dict objectForKey:@"DateTime"];
ann.coordinate = region.center;
[mapView addAnnotation:ann];
}
}
,並委託:
- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinView = nil;
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if (pinView == nil)
pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinView.pinColor = MKPinAnnotationColorPurple;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[infoButton addTarget:self action:@selector(infoButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = infoButton;
[defaultPinID release];
return pinView;
}
和信息按鈕的點擊:
-(void)infoButtonPressed:(id)sender
{
recordCatch = [[RecordCatchDetails alloc] initWithNibName:@"RecordCatchDetails" bundle:nil];
[self.view addSubview:recordCatch.view] ;
}
其中記錄美中不足的是新的類對象。
讓我更加具體。我有3個包含標題和副標題的引腳。讓我先選擇。然後有註釋標題的信息。我想單擊信息按鈕以顯示與該引腳相關的所有數據。它會調用一個新類來顯示數據。告訴我,我們將如何檢測引腳及其副標題,以便從數據庫中顯示新類中的所有數據。 – 2011-05-10 08:43:27
您將得到可以提供詳細信息的註釋,然後您可以將其傳遞到新視圖或存儲在字典中,然後傳遞它。 – visakh7 2011-05-10 08:47:29
但標題將是動態的意思來自數據庫。那麼,如果地圖上有很多針腳,我怎麼能比較標題。 – 2011-05-10 08:52:07