Problem mit custom Annotations seit xcode5

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

  • Problem mit custom Annotations seit xcode5

    Hallo Leute!

    Hab bis jetzt mit xcode4 entwickelt und hab nun natürlich vor mit xcode 5 die APPs upzudaten ... Dabei bin ich aber auf folgendes Problem gestoßen:

    Meine MapView mit den custom Annotations gibt Fehler aus bzw. killt die APP, diese hat aber in xcode4 einwandfrei funktioniert! (Das ganze passiert sobald Annotations angezeigt werden sollen)

    Vielleicht erbarmt sich kurz jemand und könnte drüberschaun, ich komm einfach nicht dahinter :(



    MapViewController.m (das wichtigste daraus)

    Quellcode

    1. - (void)updateAnnotations
    2. {
    3. if (_myLongitude != nil) {
    4. pinExists = NO;
    5. for (NSMutableDictionary *annotations in _pois)
    6. {
    7. CLLocationCoordinate2D location;
    8. location.latitude = [annotations[@"POI_LAT"] doubleValue];
    9. location.longitude = [annotations[@"POI_LONG"] doubleValue];
    10. float myLatitude = [_myLatitude floatValue];
    11. float myLongitude = [_myLongitude floatValue];
    12. CLLocation *location1 = [[CLLocation alloc] initWithLatitude:myLatitude longitude:myLongitude];
    13. CLLocation *location2 = [[CLLocation alloc] initWithLatitude:location.latitude longitude:location.longitude];
    14. if ([location1 distanceFromLocation:location2]/1000 < 5) {
    15. pinsInRadius = YES;
    16. CLLocationCoordinate2D coords = CLLocationCoordinate2DMake(location.latitude, location.longitude);
    17. AnnotationView *annotation = [[AnnotationView alloc] initWithCoordinate:coords addressDictionary:nil] ;
    18. annotation.title = [annotations objectForKey:@"POI_NAME"];
    19. annotation.image = [annotations objectForKey:@"POI_ICON"];
    20. annotation.PoiID = [annotations objectForKey:@"POI_ID"];
    21. for (AnnotationView *existAnns in self.mapView.annotations) {
    22. if ([existAnns.title isEqualToString:[annotations objectForKey:@"POI_NAME"]]) {
    23. pinExists = YES;
    24. }
    25. }
    26. if (pinExists == NO) {
    27. [self.mapView addAnnotation:annotation];
    28. }
    29. }
    30. }
    31. if (_pois != NULL) {
    32. if (pinsInRadius == YES) {
    33. _noPoisLabel.hidden = YES;
    34. } else if (pinsInRadius == NO){
    35. _loadingView.hidden = YES;
    36. _noPoisLabel.hidden = NO;
    37. }
    38. }
    39. }
    40. }
    41. - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
    42. {
    43. if ([annotation isKindOfClass:[MKUserLocation class]])
    44. return nil;
    45. MKPinAnnotationView *pinView = (MKPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@"Pin"];
    46. if (!pinView)
    47. {
    48. pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Pin"];
    49. pinView.canShowCallout=YES;
    50. pinView.annotation = annotation;
    51. pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    52. AnnotationView *myAnn = (AnnotationView *)annotation;
    53. pinView.image = [UIImage imageNamed:myAnn.image];
    54. _loadingView.hidden = YES;
    55. }
    56. else
    57. pinView.annotation = annotation;
    58. return pinView;
    59. }
    60. -(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
    61. {
    62. AnnotationView *annotapped = (AnnotationView *)view.annotation;
    63. _aktuellPoiId = annotapped.PoiID;
    64. [self.mapView setShowsUserLocation:NO];
    65. [self performSegueWithIdentifier:@"fromMapToDetail" sender:self];
    66. if(_timer)
    67. {
    68. [_timer invalidate];
    69. _timer = nil;
    70. }
    71. }
    Alles anzeigen


    AnnotationView.h

    Quellcode

    1. #import <MapKit/MapKit.h>
    2. @interface AnnotationView : MKPlacemark
    3. @property (nonatomic, readwrite, assign) CLLocationCoordinate2D coordinate1;
    4. @property (nonatomic, strong) NSString *title;
    5. @property (nonatomic, strong) NSString *subtitle;
    6. @property (nonatomic, retain) NSString *image;
    7. @property (nonatomic, strong) NSString *PoiID;
    8. @property (nonatomic, weak) NSString *entfernung;
    9. @end
    Alles anzeigen


    AnnotationView.m

    Quellcode

    1. #import "AnnotationView.h"
    2. @implementation AnnotationView
    3. - (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate2 addressDictionary:(NSDictionary *)addressDictionary
    4. {
    5. if ((self = [super initWithCoordinate:coordinate2 addressDictionary:addressDictionary]))
    6. {
    7. self.coordinate1 = coordinate2;
    8. }
    9. return self;
    10. }
    11. @end
    Alles anzeigen



    Und als Ausgabe erhalte ich:

    Quellcode

    1. 2013-09-18 18:39:14.067 MyApp[895:a0b] -[AnnotationView setTitle:]: unrecognized selector sent to instance 0xce80a20
    2. 2013-09-18 18:39:14.081 MyApp[895:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AnnotationView setTitle:]: unrecognized selector sent to instance 0xce80a20'
    3. *** First throw call stack:
    4. (
    5. 0 CoreFoundation 0x02d386f4 __exceptionPreprocess + 180
    6. 1 libobjc.A.dylib 0x01a8f8b6 objc_exception_throw + 44
    7. 2 CoreFoundation 0x02dd5983 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    8. 3 CoreFoundation 0x02d28a1b ___forwarding___ + 1019
    9. 4 CoreFoundation 0x02d285fe _CF_forwarding_prep_0 + 14
    10. 5 Steirer Guide 3D 0x0000e073 -[MapViewController updateAnnotations] + 1283
    11. 6 Foundation 0x014b9db7 __NSFireTimer + 97
    12. 7 CoreFoundation 0x02cf6d06 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 22
    13. 8 CoreFoundation 0x02cf66ed __CFRunLoopDoTimer + 1181
    14. 9 CoreFoundation 0x02cde758 __CFRunLoopRun + 1816
    15. 10 CoreFoundation 0x02cddbf3 CFRunLoopRunSpecific + 467
    16. 11 CoreFoundation 0x02cdda0b CFRunLoopRunInMode + 123
    17. 12 GraphicsServices 0x02f92a27 GSEventRunModal + 192
    18. 13 GraphicsServices 0x02f9284e GSEventRun + 104
    19. 14 UIKit 0x005faf0b UIApplicationMain + 1225
    20. 15 Steirer Guide 3D 0x00008c5d main + 141
    21. 16 libdyld.dylib 0x065bb725 start + 0
    22. )
    23. libc++abi.dylib: terminating with uncaught exception of type NSException
    24. (lldb)
    Alles anzeigen



    Ich bin für jede Hilfe dankbar!!!

    Beste Grüße
    Gerhard
  • Ok, Danke vorerst für die Hilfestellungen!

    Nur um es klar zu stellen: ich bin relativ neu in objective-c und allem drumherum, also verzeiht mir bitte wenn ich etwas nicht gleich verstehe bzw. begreife, aber ich versuchs ;)
    (In der Zwischenzeit hab ich die APP auch noch in Java geschrieben, daher ist´s umso schwieriger für mich mich wieder in den Code hier einzulesen)


    ich vermute dass Du anstelle von deiner Klasse AnnotationView eine Annotation Klasse verwenden wolltest.
    Die Annotation wird ja erst später in der Delegatemethode verwendet um den zugehörigen View zu erzeugen.


    Ok, darüber muss ich jetzt glaub ich etwas länger nachdenken um genau zu verstehen wie du das meinst... was ich nicht verstehe ist vor allem mal warum es unter xcode4 funktioniert hat?! ... Ist mein Code so geschrieben dass er nur mit Glück gerade so funktioniert?
    Im Zweifelsfall wieder auf die Suche machen nach Tutorials etc. um das ganze neu bzw. anders aufzubauen, richtig? :(

    Wenn ich

    Quellcode

    1. annotation.title = [annotations objectForKey:@"POI_NAME"];
    entferne werden die ganzen Pins mit richtigen Images etc angezeigt, als Title steht dann nach click halt überall "Vereinige Staaten" drin *g*




    was genau soll das machen?


    Hatte das nach ewiger Testerei dazu verwendet das jeweilige Image der jeweiligen View zuzuweisen (Der Name des images wird mit den restlichen Daten über json abgerufen und je nach "Kategorie" entsprechend angezeigt).


    LG ... vielleicht noch weitere Hilfestellungen? Würd mich riesig freuen, das Teil macht mir schon so kopfzerbrechen.
    Gerhard