Я открываю Detailview на аннотационной булавке, а также на tableview. Чтобы получить направление от подробностей, у меня есть следующее событие нажатия кнопки.
Отредактировано:: with -(IBAction)showDirectionUpdated; кодирование
-(IBAction)showDirectionUpdated;
{
NSIndexPath *selectedIndexPath = [self._tableView indexPathForSelectedRow];
if( selectedIndexPath == [self._tableView indexPathForSelectedRow])
{
marker *aMarker = (marker *)[appDelegate.markers objectAtIndex:selectedIndexPath.row];
NSString *EndLoc=[NSString stringWithFormat:@"%@ %@", aMarker.address,aMarker.city];
NSString* addr = [NSString stringWithFormat:@"http://maps.google.com/maps?saddr=Current Location&daddr=%@",EndLoc];
NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];
NSLog(@"%@",url);
[url release];
[self._tableView deselectRowAtIndexPath:selectedIndexPath animated:YES];
}
else
{
//here if I am opening the detailview from annotation callout button and calling
// direction in map default app. But respective address is not passing
//in default map app
NSInteger selectedIndex = [sender tag];
AddressAnnotation *selectedObject = [self.annobjs objectAtIndex:selectedIndex];
marker *aMarker = [appDelegate.markers objectAtIndex:selectedIndex];
NSString *EndLoc=[NSString stringWithFormat:@"%@ %@", aMarker.address,aMarker.city];
NSString* addr = [NSString stringWithFormat:@"http://maps.google.com/maps?saddr=Current Location&daddr=%@",EndLoc];
NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];
NSLog(@"%@",url);
[url release];
}
}
Я хочу передать отправителя или идентификатор для вызова соответствующего направления из detailView, которое я получаю при нажатии аннотации. Мне удалось получить приложение по умолчанию для направления из подробного представления, которое я получаю, выбирая табличное представление (просмотр списка). Вот некоторый код тега отправителя.
Отредактировано 2=== с помощью viewForAnnotation
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{ MKAnnotationView *annView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@""];
if (annView == nil)
{
annView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@""] autorelease];
annView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
}
annView.image = [UIImage imageNamed:@"flag.png"];
annView.annotation = annotation;
[annView setEnabled:YES];
[annView setCanShowCallout:YES];
return annView;
}
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(@"calloutAccessoryControlTapped");
MKAnnotationView* annView = (MKAnnotationView*) view;
AddressAnnotation* annotation = (AddressAnnotation*)[annView annotation];
if(BcardView.hidden == YES)
{
SearchView.hidden = YES;
BcardView.hidden = NO;
BackButtontitle.text = @"Map View";
marker *aMarker = [[marker alloc]init];
ShowroomName.text = aMarker.name;
}}
calloutAccessoryControlTapped
вместо пользовательского метода. Подход с тегами, даже если он работает, излишне сложен. - person   schedule 24.11.2011