-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和pin的创建,请帮我解释一下,因为我很冷漠:

 - (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 回答