-1

配列内の xml からデータをロードして表示するテーブル ビューがあり、すべてのセルが再入力された同じ詳細ビューを指しています。

同じビューに非表示のマップ ビューがあり、マップ ビューにはマップ内のテーブルの同じ配列が表示されます。すべての注釈には、テーブルの同じ詳細ビューを指す開示ボタンがありますが、どのように私は理解していませんマップ ビューから詳細ビューにデータを渡すことができます...

開示ボタンには、このコードを使用します

-(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 は、xml から作成された nsmutablearray の名前ですが、objectIndex が何を使用しているかわかりません...何か考えはありますか?

わかりました、ここでviewdidloadとピンの作成、私が荒涼としているので、私を助けて説明してください:

 - (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]; 

}
4

1 に答える 1

0

マップビューのすべての開示ボタンにタグを付けることをお勧めします。このタグを使用できます

[table objectAtIndex:[sender tag]];
于 2012-07-18T13:16:18.810 に答える