NSMutableDictionary in NSMutablArray durchsuchen?

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

  • NSMutableDictionary in NSMutablArray durchsuchen?

    Hi,

    ich habe eine Frage zum durchsuchen eines NSMutableDictionarys welches in einem NSMutableArray liegt:

    In meiner App lese ich die Daten aus einem XML File in ein Dictionary welches ich am Ende jedes Schleifendurchlaufes
    in ein NSMutableArray schreibe. Dieses Array verwende ich dann um die Pins auf meiner Karte anzuzeigen. Soweit so
    gut - das funktioniert auch super. So sieht mein Code aus um die Pins zu definieren:

    Quellcode

    1. while (x < [res count]) {
    2. // NSLog(@"Title: %@", [[res objectAtIndex:x] objectForKey:@"title"]);
    3. // NSLog(@"Longitude: %@", [[res objectAtIndex:x] objectForKey:@"geo:long"]);
    4. // NSLog(@"Latitude: %@", [[res objectAtIndex:x] objectForKey:@"geo:lat"]);
    5. NSLog(@"UID: %d", [NSNumber numberWithInt:[[[res objectAtIndex:x] objectForKey:@"UID"] intValue]]);
    6. CLLocationCoordinate2D c;
    7. NSString *latitude = [[res objectAtIndex:x] objectForKey:@"geo:lat"];
    8. NSString *longitude = [[res objectAtIndex:x] objectForKey:@"geo:long"];
    9. c.latitude = [latitude doubleValue];
    10. c.longitude = [longitude doubleValue];
    11. GPSAnnotation *annotation = [[GPSAnnotation alloc] initWithCoordinate:c];
    12. annotation.currentPoint = [NSNumber numberWithInt:[[[res objectAtIndex:x] objectForKey:@"UID"] intValue]];
    13. annotation.mTitle=[[res objectAtIndex:x] objectForKey:@"title"];
    14. annotation.currentRow = [res objectAtIndex:x];
    15. [mapViewOutlet addAnnotation:annotation];
    16. [annotation release];
    17. x++;
    18. }
    Alles anzeigen



    CurrentPoint zeigt die UID an - diese ID wird auch beim Klick auf den "Disclosure Button" des Pins angezeigt. Nun müsste ich herausfinden in welcher Zeile des NSMutableArray/NSMutableDictionary
    diese UID liegt.

    Quellcode

    1. - (IBAction)showLinks:(id)sender
    2. {
    3. int nrButtonPressed = ((UIButton *)sender).tag; //Liefert die UID des jeweiligen Eintrages
    4. NSString *find = [NSString stringWithFormat:@"%d", nrButtonPressed]; //Zeigt die UID richtig an
    5. NSLog(@"find: %@", find);
    6. NSUInteger index = [res indexOfObject:find]; //Liefert einen äußerst komischen Wert - das NSMutableArray hat 100 Zeilen - angezeigt wird: 2147483647
    7. NSLog(@"pressed = %i", index);
    8. NSLog(@"ButtonPressed: %d", nrButtonPressed);
    9. OnlineMapViewDetailController *controller = [[OnlineMapViewDetailController alloc] initWithNibName:@"OnlineMapViewDetailController" bundle:nil];
    10. controller.delegate = self;
    11. controller.pressed = nrButtonPressed;
    12. [self.navigationController pushViewController:controller animated:YES];
    13. [controller release];
    14. }
    Alles anzeigen



    Vielen Dank für Eure Hilfe und Eure Inputs!

    lg,

    Stefan
    AlpenApps: Apps fürs Iphone aus Österreich

    ACTC - 10.5 & Troubleshooting 10.5
  • Bosstone schrieb:


    Quellcode

    1. NSString *find = [NSString stringWithFormat:@"%d", nrButtonPressed]; //Zeigt die UID richtig an
    2. NSLog(@"find: %@", find);
    3. NSUInteger index = [res indexOfObject:find]; //Liefert einen äußerst komischen Wert - das NSMutableArray hat 100 Zeilen - angezeigt wird: 2147483647

    Was ist daran komisch?
    Du durchsuchst dein Array von Dictionaries nach einem NSString-Objekt, dass darin definitiv nicht enthalten ist.
    Du willst aber das Dictionary haben, welches diesen Inhalt des NSString-Objektes als UID hat.

    Da wirst du nur hinkommen, wenn du sinngemäß jedes [[[array object] annotation] currentPoint] mit deinem Wert vergleichst.
    Das Ding ist übrigens als Integer angelegt, da wirst du mit deinem Stringobjekt überhaupt nichts.
    «Applejack» "Don't you use your fancy mathematics to muddle the issue!"

    Iä-86! Iä-64! Awavauatsh fthagn!

    kmr schrieb:

    Ach, Du bist auch so ein leichtgläubiger Zeitgenosse, der alles glaubt, was irgendwelche Typen vor sich hin brabbeln. :-P
  • Hi,

    vielen Dank für den Lösungsansatz. Ich habe es nun folgendermaßen gelöst:

    Quellcode

    1. int x = 0;
    2. for (x=0;x < [res count];x++) {
    3. if (nrButtonPressed == [[[res objectAtIndex:x] objectForKey:@"UID"] intValue]) {
    4. OnlineMapViewDetailController *controller = [[OnlineMapViewDetailController alloc] initWithNibName:@"OnlineMapViewDetailController" bundle:nil];
    5. controller.array = [res objectAtIndex:x];
    6. controller.delegate = self;
    7. controller.pressed = nrButtonPressed;
    8. [self.navigationController pushViewController:controller animated:YES];
    9. [controller release];
    10. }
    11. }
    Alles anzeigen



    lg,

    Stefan
    AlpenApps: Apps fürs Iphone aus Österreich

    ACTC - 10.5 & Troubleshooting 10.5