Mapkit Annotation zu ViewController

H

Heinzi1991

Registriert
Thread Starter
Dabei seit
28.09.2014
Beiträge
3
Reaktionspunkte
0
Hallo liebes Forum,

ich hab ein Problem mit meiner App und hoffe ihr könnt mir dabei helfen. Also ich habe eine plist (array) und in diesem Array sind dictionaries drinnen. Mit einer fast enumination teile ich alle Sachen auf siehe Code:

Code:
[FONT=Menlo]-([COLOR=#703daa]NSMutableArray[/COLOR] *)createAnnotations[/FONT]
[FONT=Menlo]{[/FONT]
[COLOR=#703DAA][FONT=Menlo]NSMutableArray[COLOR=#000000] *annotations = [[/COLOR]NSMutableArray[COLOR=#3d1d81]new[/COLOR][COLOR=#000000]];[/COLOR][/FONT][/COLOR]

[COLOR=#008400][FONT=Menlo]//Read location details from plist[/FONT][/COLOR]
[COLOR=#3D1D81][FONT=Menlo][COLOR=#703daa]NSString[/COLOR][COLOR=#000000] *path = [[[/COLOR][COLOR=#703daa]NSBundle[/COLOR]mainBundle[COLOR=#000000]] [/COLOR]pathForResource[COLOR=#000000]:[/COLOR][COLOR=#d12f1b]@"skatepark"[/COLOR]ofType[COLOR=#000000]:[/COLOR][COLOR=#d12f1b]@"plist"[/COLOR][COLOR=#000000]];[/COLOR][/FONT][/COLOR]
[FONT=Menlo]    [COLOR=#703daa]NSArray[/COLOR] *locations = [[COLOR=#703daa]NSArray[/COLOR] [COLOR=#3d1d81]arrayWithContentsOfFile[/COLOR]:path];[/FONT]


[FONT=Menlo]    [COLOR=#bb2ca2]for[/COLOR] ([COLOR=#703daa]NSDictionary[/COLOR] *row [COLOR=#bb2ca2]in[/COLOR] locations)[/FONT]
[FONT=Menlo]    {[/FONT]
[FONT=Menlo]        [COLOR=#703daa]NSNumber[/COLOR] *latitude = [row [COLOR=#3d1d81]objectForKey[/COLOR]:[COLOR=#d12f1b]@"latitude"[/COLOR]];[/FONT]
[FONT=Menlo]        [COLOR=#703daa]NSNumber[/COLOR] *longitude = [row [COLOR=#3d1d81]objectForKey[/COLOR]:[COLOR=#d12f1b]@"longitude"[/COLOR]];[/FONT]
[FONT=Menlo]        [COLOR=#703daa]NSString[/COLOR] *title = [row [COLOR=#3d1d81]objectForKey[/COLOR]:[COLOR=#d12f1b]@"title"[/COLOR]];[/FONT]


[COLOR=#008400][FONT=Menlo]//Create coordinates from the latitude and longitude values[/FONT][/COLOR]
[COLOR=#703DAA][FONT=Menlo]CLLocationCoordinate2D[COLOR=#000000] coord;[/COLOR][/FONT][/COLOR]

[FONT=Menlo]        coord.[COLOR=#703daa]latitude[/COLOR] = latitude.[COLOR=#703daa]doubleValue[/COLOR];[/FONT]
[FONT=Menlo]        coord.[COLOR=#703daa]longitude[/COLOR] = longitude.[COLOR=#703daa]doubleValue[/COLOR];[/FONT]

[FONT=Menlo]        [COLOR=#4f8187]MapViewAnnotation[/COLOR] *annotation = [[[COLOR=#4f8187]MapViewAnnotation[/COLOR] [COLOR=#3d1d81]alloc[/COLOR]] [COLOR=#31595d]initWithTitle[/COLOR]:title [COLOR=#31595d]AndCoordinate[/COLOR]:coord];[/FONT]

[FONT=Menlo]        [annotations [COLOR=#3d1d81]addObject[/COLOR]:annotation];[/FONT]

[FONT=Menlo]    }
  return annotations;
}[/FONT]

Diese Punkte werden dann auf der Map angezeigt und wenn man den Pin anklickt, habe ich rechts ein Info Button. Mir ist es noch gelungen, wenn man den Button drückt das ein neuer ViewController angezeigt wird. Nun möchte ich aber, das der Titel des ViewControllers und ein Label den gleichen Titel haben, wie der Titel des Pin und da scheitere ich zurzeit.

Hoffe mir kann jemand helfen und wenn ihr noch was braucht einfach sagen.
 
du kannst dem button einen tag zuweisen, z.B. den index des Dictionarys im array , wenn du dann auf einen button touched sieht deine methode zB so aus

- (void)touchButton:(UIButton *)sender
{
NSDictionary *myDict = array[sender.tag];

....
}

und dann kannst du deinem ViewController deine daten aus deinem myDict übergeben, bzw auch da komplette Dictionary und lässt den ViewController dann damit machen was richtig ist
 
Also ich verstehe einigermaßen was du meinst, aber ich hab es mit einem segue gemacht.

hier der code:

Code:
[FONT=Menlo]-([COLOR=#bb2ca2]void[/COLOR])info:([COLOR=#bb2ca2]id[/COLOR])sender[/FONT]
[FONT=Menlo]{[/FONT]
[COLOR=#D12F1B][FONT=Menlo][COLOR=#000000]    [/COLOR][COLOR=#3d1d81]NSLog[/COLOR][COLOR=#000000]([/COLOR]@"Button gedrückt"[COLOR=#000000]);[/COLOR][/FONT][/COLOR]
[COLOR=#3D1D81][FONT=Menlo][COLOR=#000000]    [[/COLOR][COLOR=#bb2ca2]self[/COLOR][COLOR=#000000] [/COLOR]performSegueWithIdentifier[COLOR=#000000]:[/COLOR][COLOR=#d12f1b]@"detailsSegue"[/COLOR][COLOR=#000000] [/COLOR]sender[COLOR=#000000]:sender];[/COLOR][/FONT][/COLOR]
[FONT=Menlo]}[/FONT]
[FONT=Menlo]
[/FONT]
[FONT=Menlo]-([COLOR=#bb2ca2]void[/COLOR])prepareForSegue:([COLOR=#703daa]UIStoryboardSegue[/COLOR] *)segue sender:([COLOR=#bb2ca2]id[/COLOR])sender[/FONT]
[FONT=Menlo]{[/FONT]
[COLOR=#D12F1B][FONT=Menlo][COLOR=#000000]    [/COLOR][COLOR=#3d1d81]NSLog[/COLOR][COLOR=#000000]([/COLOR]@"Gut angekommen"[COLOR=#000000]);[/COLOR][/FONT][/COLOR]
[COLOR=#703DAA][FONT=Menlo][COLOR=#000000]    [/COLOR][COLOR=#4f8187]DetailViewController[/COLOR][COLOR=#000000] *dvc = segue.[/COLOR]destinationViewController[COLOR=#000000];[/COLOR][/FONT][/COLOR]
[FONT=Menlo]    dvc.[COLOR=#4f8187]name[/COLOR] = [COLOR=#d12f1b]@"Hello"[/COLOR];[/FONT]
[FONT=Menlo]    dvc.[COLOR=#703daa]title[/COLOR] = [COLOR=#d12f1b]@"Hello"[/COLOR];[/FONT]
[COLOR=#BB2CA2][FONT=Menlo][COLOR=#000000]    [/COLOR]return[COLOR=#000000];[/COLOR][/FONT][/COLOR]

ist das falsch bzw ungünstig bei so einem problem? bzw wie kann ich es richtig machen damit der dvc.name und dvc.title den gleichen title hat wie der pin
 
ob du es per addTarget oder per Segue machst ändert nichts dran, in deinem prepareForSegue heißt der Parameter auch sender , siehe oben

deinem Button einen Tag zuweisen (index aus dem Array) und im prepareForSegue per tag/index aufs array zugreifen

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
UIButton *button = (UIButton *)sender;
NSDictionary *myDict = array[button.tag];
DetailViewController *dvc = segue.destinationViewController;
dvc.name = myDict[@"name"];
dvc.title = myDict[@"title"];

return;
}
 
Danke für deine Hilfe und deine Tipps, es funktioniert noch nicht so ganz weil das Array als undeclared identifier bezeichnet wird, aber ich werde es schon irgendwie schaffen
aber danke für deine Hilfe
 
Zurück
Oben Unten