Hallo,
ich habe eine Frage zu MapKit. Ich habe diesem Thema eine kleine DEMO-App angehangen, damit ihr gleich wisst worum es geht.
Ich habe eine App zum Testen gebaut, in der ein MapView angezeigt wird. Mit wenigen Buttons kann man Art der Karte einstellen, Pins setzen und auf Deutschland zoomen.
Mein Anspruch wäre nun noch folgendes: Ich setze zwei Pins und möchte auch beide mit einem PNG ausstatten. Wenn ich nur einen Pin anpassen möchte funktioniert es:
Alles anzeigen
Wenn ich nun aber beide Pins unterschiedlich anpassen möchte stürzt die App ohne Log-Eintrag ab:
Alles anzeigen
Daher nun meine Frage. Warum passiert dies? Was mache ich noch falsch?
Weiterhin beschäftigt mich noch folgendes:
- Warum überschreibt es beim Setzen von Pins immer den blauen Punkt von UserLocation? Kann man das verhindern?
- Wie kann ich den Klick auf den Button im PopUp (annotationViewClick) differenziert nutzen, also mal dieses Ereignis, mal jenes? Da habe ich noch keine Idee wie ich das abfragen soll, welcher Pin das gerade ist. Oder an welcher Stelle kann ich eine ID mitgeben oder ähnliches?
Vielen Dank schonmal.
Gruß
Daniel
ich habe eine Frage zu MapKit. Ich habe diesem Thema eine kleine DEMO-App angehangen, damit ihr gleich wisst worum es geht.
Ich habe eine App zum Testen gebaut, in der ein MapView angezeigt wird. Mit wenigen Buttons kann man Art der Karte einstellen, Pins setzen und auf Deutschland zoomen.
Mein Anspruch wäre nun noch folgendes: Ich setze zwei Pins und möchte auch beide mit einem PNG ausstatten. Wenn ich nur einen Pin anpassen möchte funktioniert es:
Quellcode
- if ([annotation isKindOfClass:[MapAnnotation class]]) {
- MKAnnotationView* customAnnotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil] autorelease];
- customAnnotationView.image = [UIImage imageNamed:@"pin1.png"];
- customAnnotationView.canShowCallout = YES;
- UIImageView *leftIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pin1.png"]];
- customAnnotationView.leftCalloutAccessoryView = leftIconView;
- UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
- [rightButton addTarget:self action:@selector(annotationViewClick:) forControlEvents:UIControlEventTouchUpInside];
- customAnnotationView.rightCalloutAccessoryView = rightButton;
- return customAnnotationView;
- }
Wenn ich nun aber beide Pins unterschiedlich anpassen möchte stürzt die App ohne Log-Eintrag ab:
Quellcode
- if ([annotation isKindOfClass:[MapAnnotation class]]) {
- MKAnnotationView* customAnnotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil] autorelease];
- customAnnotationView.image = [UIImage imageNamed:@"pin1.png"];
- customAnnotationView.canShowCallout = YES;
- UIImageView *leftIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pin1.png"]];
- customAnnotationView.leftCalloutAccessoryView = leftIconView;
- UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
- [rightButton addTarget:self action:@selector(annotationViewClick:) forControlEvents:UIControlEventTouchUpInside];
- customAnnotationView.rightCalloutAccessoryView = rightButton;
- return customAnnotationView;
- }
- if ([annotation isKindOfClass:[MapAnnotation2 class]]) {
- MKAnnotationView* customAnnotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil] autorelease];
- customAnnotationView.image = [UIImage imageNamed:@"pin2.png"];
- customAnnotationView.canShowCallout = YES;
- UIImageView *leftIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pin2.png"]];
- customAnnotationView.leftCalloutAccessoryView = leftIconView;
- UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
- [rightButton addTarget:self action:@selector(annotationViewClick:) forControlEvents:UIControlEventTouchUpInside];
- customAnnotationView.rightCalloutAccessoryView = rightButton;
- return customAnnotationView;
- }
Daher nun meine Frage. Warum passiert dies? Was mache ich noch falsch?
Weiterhin beschäftigt mich noch folgendes:
- Warum überschreibt es beim Setzen von Pins immer den blauen Punkt von UserLocation? Kann man das verhindern?
- Wie kann ich den Klick auf den Button im PopUp (annotationViewClick) differenziert nutzen, also mal dieses Ereignis, mal jenes? Da habe ich noch keine Idee wie ich das abfragen soll, welcher Pin das gerade ist. Oder an welcher Stelle kann ich eine ID mitgeben oder ähnliches?
Vielen Dank schonmal.
Gruß
Daniel