Array Object Index vom ausgewählten Element herausfinden

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Array Object Index vom ausgewählten Element herausfinden

    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.

    Quellcode

    1. //calloutAccessoryControlTapped
    2. - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
    3. if ([(UIButton*)control buttonType] == UIButtonTypeDetailDisclosure)
    4. {
    5. if (![view.annotation isKindOfClass:[PlaceMark class]])
    6. return;
    7. // use the annotation view as the sender
    8. [self performSegueWithIdentifier:@"mapDetailPage" sender:view];
    9. // Do your thing when the detailDisclosureButton is touched
    10. UIViewController *vumLocationViewController = [[UIViewController alloc] init];
    11. [[self navigationController] pushViewController:vumLocationViewController animated:YES];
    12. }
    13. else if([(UIButton*)control buttonType] == UIButtonTypeInfoDark)
    14. {
    15. // Do your thing when the infoDarkButton is touched
    16. NSLog(@"infoDarkButton for longitude: %f and latitude: %f",
    17. [(PlaceMark*)[view annotation] coordinate].longitude,
    18. [(PlaceMark*)[view annotation] coordinate].latitude);
    19. }
    20. }
    21. -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    22. {
    23. if ([segue.identifier isEqualToString:@"mapDetailPage"]) {
    24. vumLocationViewController *vvc = segue.destinationViewController;
    25. //vvc.profilId = sender.annotation;
    26. //vvc.receivedLocation = sender.placeMark;
    27. NSIndexPath *indexPath = [self.locationsArray objectAtIndex:1];
    28. vvc.profilId = [[self.parser.locationsArray objectAtIndex:indexPath] profilId];
    29. vvc.coverImageUrl = [[self.parser.locationsArray objectAtIndex:indexPath] coverImageUrl];
    30. return;
    31. }
    32. }
    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.

    Quellcode

    1. #pragma mark - CLLocationManagerDelegate
    2. - (void)locationManager:(CLLocationManager *)manager
    3. didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    4. if ((oldLocation.coordinate.longitude != newLocation.coordinate.longitude)
    5. || (oldLocation.coordinate.latitude != newLocation.coordinate.latitude)) {
    6. CLLocationCoordinate2D coord = {
    7. .latitude = newLocation.coordinate.latitude,
    8. .longitude = newLocation.coordinate.longitude};
    9. MKCoordinateRegion region;
    10. region.center = coord;
    11. MKCoordinateSpan span = {.latitudeDelta = 0.1, .longitudeDelta = 0.1};
    12. region.span = span;
    13. [myMapView setRegion:region];
    14. for(int i = 0; i < [self.parser.locationsArray count]; i++)
    15. {
    16. double latitude = [[[self.parser.locationsArray objectAtIndex:i] latitude] doubleValue];
    17. double longitude = [[[self.parser.locationsArray objectAtIndex:i] longitude] doubleValue];
    18. coord.latitude = latitude;
    19. coord.longitude = longitude;
    20. PlaceMark *placeMark = [[PlaceMark alloc]
    21. initWithCoordinate:coord
    22. andMarkTitle: [[self.parser.locationsArray objectAtIndex:i] displayName]
    23. andMarkSubTitle:[[self.parser.locationsArray objectAtIndex:i] description]];
    24. [myMapView addAnnotation:placeMark];
    25. placeMark = nil;
    26. }
    27. }
    28. }
    29. //view For Annotation
    30. - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
    31. static NSString *identifier = @"myLocation";
    32. if ([annotation isKindOfClass:[PlaceMark class]]) {
    33. MKPinAnnotationView *annotationView =
    34. (MKPinAnnotationView *)[myMapView dequeueReusableAnnotationViewWithIdentifier:identifier];
    35. if (annotationView == nil)
    36. {
    37. annotationView = [[MKPinAnnotationView alloc]
    38. initWithAnnotation:annotation
    39. reuseIdentifier:identifier];
    40. }
    41. else
    42. {
    43. annotationView.annotation = annotation;
    44. }
    45. annotationView.enabled = YES;
    46. annotationView.canShowCallout = YES;
    47. // Create a UIButton object to add on the
    48. UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    49. [rightButton setTitle:annotation.title forState:UIControlStateNormal];
    50. [annotationView setRightCalloutAccessoryView:rightButton];
    51. return annotationView;
    52. }
    53. return nil;
    54. }
    Alles anzeigen


    hat da jemand eine Idee wie ich das lösen kann?