Moin,
ich hab nen kleines Problemchen.
Ich habe eine XML Datei, die von einem Parser eingelesen wird und dann als Array wieder ausgespuckt wird.
Soweit so gut. Dann habe ich einen UIViewController mit dem MKMapView.
Nun wird ein Teil der Daten aus dem Array benutzt um die Annotations zu erzeugen.
Jede Pinnadel hat dann auch einen kleinen Button auf den man draufdrücken kann um zu einem anderen viewController zukommen der weitere Daten aus der XML anzeigen soll. Nun hab ich das Problem, dass ich bei dem übergeben der Daten (siehe Code) nicht weiß wie ich angeben soll welches Objekt es nun aus dem Array ist, da es ja nicht wie beim UITableView mit "selectedRow" geht.
Alles anzeigen
das sind die beiden letzten Methoden wobei die untere eigentlich relevant sein sollte. Und das Problem was ich nun habe ist, das ich den indexPath nicht bestimmen kann. Momentan steht er auf 1 aber ich möchte ja gerne die Reihe auswählen, wovon ich auch die Pinnadel angeklickt habe.
Hier ist nochmal der restlichen Code, der relevant sein könnte.
Alles anzeigen
hat da jemand eine Idee wie ich das lösen kann?
ich hab nen kleines Problemchen.
Ich habe eine XML Datei, die von einem Parser eingelesen wird und dann als Array wieder ausgespuckt wird.
Soweit so gut. Dann habe ich einen UIViewController mit dem MKMapView.
Nun wird ein Teil der Daten aus dem Array benutzt um die Annotations zu erzeugen.
Jede Pinnadel hat dann auch einen kleinen Button auf den man draufdrücken kann um zu einem anderen viewController zukommen der weitere Daten aus der XML anzeigen soll. Nun hab ich das Problem, dass ich bei dem übergeben der Daten (siehe Code) nicht weiß wie ich angeben soll welches Objekt es nun aus dem Array ist, da es ja nicht wie beim UITableView mit "selectedRow" geht.
Quellcode
- //calloutAccessoryControlTapped
- - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
- if ([(UIButton*)control buttonType] == UIButtonTypeDetailDisclosure)
- {
- if (![view.annotation isKindOfClass:[PlaceMark class]])
- return;
- // use the annotation view as the sender
- [self performSegueWithIdentifier:@"mapDetailPage" sender:view];
- // Do your thing when the detailDisclosureButton is touched
- UIViewController *vumLocationViewController = [[UIViewController alloc] init];
- [[self navigationController] pushViewController:vumLocationViewController animated:YES];
- }
- else if([(UIButton*)control buttonType] == UIButtonTypeInfoDark)
- {
- // Do your thing when the infoDarkButton is touched
- NSLog(@"infoDarkButton for longitude: %f and latitude: %f",
- [(PlaceMark*)[view annotation] coordinate].longitude,
- [(PlaceMark*)[view annotation] coordinate].latitude);
- }
- }
- -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
- {
- if ([segue.identifier isEqualToString:@"mapDetailPage"]) {
- vumLocationViewController *vvc = segue.destinationViewController;
- //vvc.profilId = sender.annotation;
- //vvc.receivedLocation = sender.placeMark;
- NSIndexPath *indexPath = [self.locationsArray objectAtIndex:1];
- vvc.profilId = [[self.parser.locationsArray objectAtIndex:indexPath] profilId];
- vvc.coverImageUrl = [[self.parser.locationsArray objectAtIndex:indexPath] coverImageUrl];
- return;
- }
- }
das sind die beiden letzten Methoden wobei die untere eigentlich relevant sein sollte. Und das Problem was ich nun habe ist, das ich den indexPath nicht bestimmen kann. Momentan steht er auf 1 aber ich möchte ja gerne die Reihe auswählen, wovon ich auch die Pinnadel angeklickt habe.
Hier ist nochmal der restlichen Code, der relevant sein könnte.
Quellcode
- #pragma mark - CLLocationManagerDelegate
- - (void)locationManager:(CLLocationManager *)manager
- didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
- if ((oldLocation.coordinate.longitude != newLocation.coordinate.longitude)
- || (oldLocation.coordinate.latitude != newLocation.coordinate.latitude)) {
- CLLocationCoordinate2D coord = {
- .latitude = newLocation.coordinate.latitude,
- .longitude = newLocation.coordinate.longitude};
- MKCoordinateRegion region;
- region.center = coord;
- MKCoordinateSpan span = {.latitudeDelta = 0.1, .longitudeDelta = 0.1};
- region.span = span;
- [myMapView setRegion:region];
- for(int i = 0; i < [self.parser.locationsArray count]; i++)
- {
- double latitude = [[[self.parser.locationsArray objectAtIndex:i] latitude] doubleValue];
- double longitude = [[[self.parser.locationsArray objectAtIndex:i] longitude] doubleValue];
- coord.latitude = latitude;
- coord.longitude = longitude;
- PlaceMark *placeMark = [[PlaceMark alloc]
- initWithCoordinate:coord
- andMarkTitle: [[self.parser.locationsArray objectAtIndex:i] displayName]
- andMarkSubTitle:[[self.parser.locationsArray objectAtIndex:i] description]];
- [myMapView addAnnotation:placeMark];
- placeMark = nil;
- }
- }
- }
- //view For Annotation
- - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
- static NSString *identifier = @"myLocation";
- if ([annotation isKindOfClass:[PlaceMark class]]) {
- MKPinAnnotationView *annotationView =
- (MKPinAnnotationView *)[myMapView dequeueReusableAnnotationViewWithIdentifier:identifier];
- if (annotationView == nil)
- {
- annotationView = [[MKPinAnnotationView alloc]
- initWithAnnotation:annotation
- reuseIdentifier:identifier];
- }
- else
- {
- annotationView.annotation = annotation;
- }
- annotationView.enabled = YES;
- annotationView.canShowCallout = YES;
- // Create a UIButton object to add on the
- UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
- [rightButton setTitle:annotation.title forState:UIControlStateNormal];
- [annotationView setRightCalloutAccessoryView:rightButton];
- return annotationView;
- }
- return nil;
- }
hat da jemand eine Idee wie ich das lösen kann?