-1

I have a table view that load the data from an xml in a array and show it, every cell point to the same detail view repopulated.

In the same view i have a hidden map view, the map view show the same array of the table in the map, every annotation have a disclosure button that point to the same detail view of the table, but i don't understand how i can pass the data from the map view to the detail view...

for the disclosure button i use this code

-(IBAction)showDetails:(id)sender{

DettMercatiViewController *dettMercatiViewController = [[DettMercatiViewController alloc] initWithNibName:@"DettMercatiViewController" bundle:nil];
dettMercatiViewController.mieiMercati = [table objectAtIndex:????];
[self.navigationController pushViewController:dettMercatiViewController animated:YES];
[dettMercatiViewController release]; 

}

table is the name of the nsmutablearray created from the xml but i don't know what objectIndex use... any idea?

ok, here the viewdidload and the creation of pin, please help me and explain because i am desolate:

 - (void)viewDidLoad
{
    pp =0;

//Colore NavigationBar
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:33.0f/255.0f green:89.0f/255.0f blue:50.0f/255.0f alpha:1.0f];

//Font Navigation Bar
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 45)];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont fontWithName:@"Museo700-Regular" size:20];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.textAlignment = UITextAlignmentCenter;
label.textColor =[UIColor whiteColor];
label.text=[self.title uppercaseString];  
self.navigationItem.titleView = label; 
[label release];


//creazione nome XML
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *nomeXML = [NSString stringWithFormat: @"%@_%@_%@",[defaults stringForKey:@"interesse"],[defaults stringForKey:@"provincia"],[defaults stringForKey:@"giorno"]]; 

NSLog(@"%@", nomeXML);

//Caricamento XML
table = [[NSMutableArray alloc] init];  
NSString *url = [[NSBundle mainBundle] pathForResource:nomeXML ofType:@"xml"];
XMLParser *myParser = [[[XMLParser alloc]autorelease] parseXMLAtURL:url toObject:@"Mercato" parseError:nil];

for(int i = 0; i < [[myParser items] count]; i++) {
    Mercato *new = [[myParser items] objectAtIndex:i];
    [table addObject:new];





///////////////////////////////////////////
//definizione posizione utente

AppDelegate *appDelegate=(AppDelegate *)[UIApplication sharedApplication].delegate;


CLLocation *userLoc = appDelegate.locationManager.location;
CLLocationCoordinate2D userCoordinate = userLoc.coordinate;

NSLog(@"user latitude = %f",userCoordinate.latitude);
NSLog(@"user longitude = %f",userCoordinate.longitude);

mapView.delegate=self;


//Pin Mappa


    CLLocationCoordinate2D theCoordinate;
    theCoordinate.latitude = [new.latitudine doubleValue];
    theCoordinate.longitude = [new.longitudine doubleValue];

    myAnnotation=[[MyAnnotation alloc] init];


    myAnnotation.coordinate=theCoordinate;
    myAnnotation.title=[NSString stringWithFormat:@"%@", new.ubicazione];
    myAnnotation.subtitle=[NSString stringWithFormat:@"%@, %@, %@",new.comune, new.giorno, new. orario];




    [mapView addAnnotation:myAnnotation];

    [annotations addObject:myAnnotation];


    if([new.latitudine doubleValue] == 0) {
        [mapView removeAnnotation:myAnnotation];
        myAnnotation = nil;
    }


    // Inizializza mappa al Centro della Provincia

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    if (([[defaults stringForKey:@"provincia"] isEqualToString:@"bergamo"])) {
        MKCoordinateRegion newRegion;
        newRegion.center.latitude = 45.6982642;
        newRegion.center.longitude = 9.6772698;
        newRegion.span.latitudeDelta = 0.512872;
        newRegion.span.longitudeDelta = 0.509863;
        [mapView setRegion:newRegion animated:YES];
    }

    if (([[defaults stringForKey:@"provincia"] isEqualToString:@"brescia"])) {
        MKCoordinateRegion newRegion;
        newRegion.center.latitude = 45.5411875;
        newRegion.center.longitude = 10.2194437;
        newRegion.span.latitudeDelta = 0.512872;
        newRegion.span.longitudeDelta = 0.509863;
        [mapView setRegion:newRegion animated:YES];
    }

    if (([[defaults stringForKey:@"provincia"] isEqualToString:@"como"])) {
        MKCoordinateRegion newRegion;
        newRegion.center.latitude = 45.8080597;
        newRegion.center.longitude = 9.0851765;
        newRegion.span.latitudeDelta = 0.512872;
        newRegion.span.longitudeDelta = 0.509863;
        [mapView setRegion:newRegion animated:YES];
    }

    if (([[defaults stringForKey:@"provincia"] isEqualToString:@"cremona"])) {
        MKCoordinateRegion newRegion;
        newRegion.center.latitude = 45.133249;
        newRegion.center.longitude = 10.0226511;
        newRegion.span.latitudeDelta = 0.512872;
        newRegion.span.longitudeDelta = 0.509863;
        [mapView setRegion:newRegion animated:YES];
    }

    if (([[defaults stringForKey:@"provincia"] isEqualToString:@"lecco"])) {
        MKCoordinateRegion newRegion;
        newRegion.center.latitude = 45.8565698;
        newRegion.center.longitude = 9.3976704;
        newRegion.span.latitudeDelta = 0.512872;
        newRegion.span.longitudeDelta = 0.509863;
        [mapView setRegion:newRegion animated:YES];
    }

    if (([[defaults stringForKey:@"provincia"] isEqualToString:@"lodi"])) {
        MKCoordinateRegion newRegion;
        newRegion.center.latitude = 45.3138041;
        newRegion.center.longitude = 9.5018274;
        newRegion.span.latitudeDelta = 0.512872;
        newRegion.span.longitudeDelta = 0.509863;
        [mapView setRegion:newRegion animated:YES];
    }

    if (([[defaults stringForKey:@"provincia"] isEqualToString:@"mantova"])) {
        MKCoordinateRegion newRegion;
        newRegion.center.latitude = 45.1564168;
        newRegion.center.longitude = 10.7913751;
        newRegion.span.latitudeDelta = 0.512872;
        newRegion.span.longitudeDelta = 0.509863;
        [mapView setRegion:newRegion animated:YES];
    }

    if (([[defaults stringForKey:@"provincia"] isEqualToString:@"milano"])) {
        MKCoordinateRegion newRegion;
        newRegion.center.latitude = 45.4654542;
        newRegion.center.longitude = 9.186516;
        newRegion.span.latitudeDelta = 0.512872;
        newRegion.span.longitudeDelta = 0.512872;
        [mapView setRegion:newRegion animated:YES];
    }

    if (([[defaults stringForKey:@"provincia"] isEqualToString:@"monza e brianza"])) {
        MKCoordinateRegion newRegion;
        newRegion.center.latitude = 45.623599;
        newRegion.center.longitude = 9.2588015;
        newRegion.span.latitudeDelta = 0.512872;
        newRegion.span.longitudeDelta = 0.509863;
        [mapView setRegion:newRegion animated:YES];
    }

    if (([[defaults stringForKey:@"provincia"] isEqualToString:@"pavia"])) {
        MKCoordinateRegion newRegion;
        newRegion.center.latitude = 45.1847248;
        newRegion.center.longitude = 9.1582069;
        newRegion.span.latitudeDelta = 0.512872;
        newRegion.span.longitudeDelta = 0.509863;
        [mapView setRegion:newRegion animated:YES];
    }

    if (([[defaults stringForKey:@"provincia"] isEqualToString:@"sondrio"])) {
        MKCoordinateRegion newRegion;
        newRegion.center.latitude = 46.1698583;
        newRegion.center.longitude = 9.8787674;
        newRegion.span.latitudeDelta = 0.512872;
        newRegion.span.longitudeDelta = 0.509863;
        [mapView setRegion:newRegion animated:YES];
    }

    if (([[defaults stringForKey:@"provincia"] isEqualToString:@"varese"])) {
        MKCoordinateRegion newRegion;
        newRegion.center.latitude = 45.8205989;
        newRegion.center.longitude = 8.8250576;
        newRegion.span.latitudeDelta = 0.512872;
        newRegion.span.longitudeDelta = 0.509863;
        [mapView setRegion:newRegion animated:YES];
    }


}
////////////////////////////

    [super viewDidLoad];

   }


 #pragma mark MKMapViewDelegate

 - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
NSLog(@"welcome into the map view annotation");
pp++;

// if it's the user location, just return nil.
if ([annotation isKindOfClass:[MKUserLocation class]]){

    return nil;

}

// try to dequeue an existing pin view first
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:myAnnotation reuseIdentifier:AnnotationIdentifier]autorelease];
pinView.animatesDrop=YES;
pinView.canShowCallout=YES;
pinView.pinColor=MKPinAnnotationColorGreen;
pinView.tag = pp;

UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

[rightButton setTitle:myAnnotation.title forState:UIControlStateNormal];
[rightButton addTarget:self
                action:@selector(showDetails:)
      forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = rightButton;

return pinView;


 }

  ////////////////
   -(IBAction)showDetails:(id)sender{

    NSLog(@"%i", pp);

   DettMercatiViewController *dettMercatiViewController = [[DettMercatiViewController alloc]  initWithNibName:@"DettMercatiViewController" bundle:nil];
dettMercatiViewController.mieiMercati = [table objectAtIndex:[sender tag]];
[self.navigationController pushViewController:dettMercatiViewController animated:YES];
[dettMercatiViewController release]; 

}
Brad Larson
  • 170,088
  • 45
  • 397
  • 571
Acunamatata
  • 55
  • 2
  • 9
  • I don't recommend the tag approach. There's a much more direct way to access the annotation that was tapped. For examples, see [this](http://stackoverflow.com/questions/9462699/how-to-recognize-which-pin-was-tapped) and [this](http://stackoverflow.com/questions/9876042/annotation-details-after-detail-disclosure-pressed). –  Jul 18 '12 at 13:28

1 Answers1

0

I suggest to give every disclosure button in your map view a tag and you can use this tag than so

[table objectAtIndex:[sender tag]];