Usuwanie adnotacji z mojego widoku mapy w następujący sposób:MKMapView - Usuwanie adnotacji powoduje awarii aplikacji
if ([[self.mapView annotations] count] > 0)
{
[self.mapView removeAnnotations:[self.mapView annotations]];
}
powoduje mój wniosek do zderzenia z następującym wyjątkiem:
*** 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.'
Adnotacje są dodanej następujący sposób:
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];
}
My PFAnnotation.h jest:
@interface PFAnnotation : NSObject <MKAnnotation>
{
NSString *stationName;
CLLocationCoordinate2D stationPosition;
NSNumber *stationLength;
}
@property (nonatomic, retain) NSString *stationName;
@property CLLocationCoordinate2D stationPosition;
@property (nonatomic, retain) NSNumber *stationLength;
@end
i mój PFAnnotation.m jest:
@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];
}
Czytałem w innych wątkach, że ustawienie właściwości adnotacji z wątku tła jest powód, dla powyższego błędu. Ale w moim przypadku tak nie jest, ponieważ wszystko jest wykonywane w głównym wątku. Proszę doradź.
proszę podać kod dodający adnotacje. Dzięki! –
@Guntis Treulands Edytowałem pytanie i dodałem kod. Proszę zobaczyć. – DroidHeaven
co się stanie, gdy nie ustawisz nazwa stacji i długość stacji? czy nadal się zawiesza? –