rimozione delle annotazioni dal mio guarda la mappa nel modo seguente:MKMapView - Rimozione annotazione provoca incidente app
if ([[self.mapView annotations] count] > 0)
{
[self.mapView removeAnnotations:[self.mapView annotations]];
}
provoca la mia domanda di crash con la seguente eccezione:
*** Terminating app due to uncaught exception 'NSRangeException', reason: 'Cannot remove an observer <MKAnnotationContainerView 0xe87b420> for the key path "title" from <PFAnnotation 0x10851230> because it is not registered as an observer.'
Le annotazioni vengono aggiunti in nel seguente modo:
CLLocationCoordinate2D pinPosition;
for (int index = 0; index < [array count]; index++)
{
Station *aStation = [array objectAtIndex:index];
PFAnnotation *stationPin = [[PFAnnotation alloc] init]; //StationPinView
pinPosition = CLLocationCoordinate2DMake([[aStation valueForKey:@"latitude"] doubleValue], [[aStation valueForKey:@"longitude"] doubleValue]);
stationPin.stationName = [aStation valueForKey:@"stationName"];
stationPin.stationPosition = pinPosition;
stationPin.stationLength = [aStation valueForKey:@"platformLength"];
[self.mapView addAnnotation:stationPin];
[stationPin release];
}
mio PFAnnotation.h è:
@interface PFAnnotation : NSObject <MKAnnotation>
{
NSString *stationName;
CLLocationCoordinate2D stationPosition;
NSNumber *stationLength;
}
@property (nonatomic, retain) NSString *stationName;
@property CLLocationCoordinate2D stationPosition;
@property (nonatomic, retain) NSNumber *stationLength;
@end
e la mia PFAnnotation.m è:
@implementation PFAnnotation
@synthesize stationName;
@synthesize stationPosition;
@synthesize stationLength;
- (CLLocationCoordinate2D)coordinate;
{
return stationPosition;
}
- (NSString *)title
{
return stationName;
}
- (NSString *)subtitle
{
if (stationLength == nil)
return nil;
else
return [NSString stringWithFormat:@"Platform Length: %@ft",stationLength];
}
- (void)dealloc {
[stationName release];
[stationLength release];
[super dealloc];
}
Ho letto in alcuni altri fili che, l'impostazione delle proprietà delle annotazioni dal thread in background è la ragione per l'errore precedente. Ma nel mio caso, non è così perché ogni cosa viene eseguita sul thread principale. Si prega di avvisare.
per favore aggiungi del codice come aggiungi le annotazioni in primo luogo.! Grazie! –
@Guntis Treulands Ho modificato la domanda e aggiunto il codice. Perfavore guarda. – DroidHeaven
cosa succede quando non si imposta stationName e stationLength? si schianta ancora? –