なぜこのエラーが発生し、困惑したのか理解できないようです。
クラスPlaceMarkのインスタンス0x7c763e0は、キー値オブザーバーがまだ登録されている間に割り当てが解除されました。観測情報が漏洩し、他の物体に誤って付着する可能性もあります。NSKVODeallocateBreakにブレークポイントを設定して、デバッガーでここで停止します。現在の観測情報は次のとおりです。
<NSKeyValueObservationInfo 0x7c77220> ( <NSKeyValueObservance 0x7c77070: Observer: 0x7ba10c0, Key path: coordinate, Options: <New: NO, Old: NO, Prior: YES> Context: 0x0, Property: 0x7c76b00>)
私のPlistの例:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>caloosahatchee</key>
<array>
<dict>
<key>name</key>
<string>Punta Rassa Boat Ramp</string>
<key>latitude</key>
<string>26.48444444444444</string>
<key>longitude</key>
<string>-82.010277777777778</string>
<key>coordinates</key>
<string>N26 29 04 W81 00 37</string>
<key>description</key>
<string>Boat ramp with fish cleaning station and several long docks.\n(239) 533-7275</string>
<key>icons</key>
<string>CFILH</string>
</dict>
<dict>
<key>name</key>
<string>Cape Harbour</string>
<key>latitude</key>
<string>26.48015</string>
<key>longitude</key>
<string>-81.96936</string>
<key>coordinates</key>
<string>N26 32 38 W82 00 28</string>
<key>description</key>
<string>Marina with bait/tackle shop, kayak rentals and access to restaurant and shops. Boat docks and paddle craft landing.\n(239) 945-4330</string>
<key>icons</key>
<string>FNLJI</string>
</dict>
<dict>
<key>name</key>
<string>Tarpon Point</string>
<key>latitude</key>
<string>26.53922222222222</string>
<key>longitude</key>
<string>-82.00027777777777778</string>
<key>coordinates</key>
<string>N26 32 21.2 W82 00 01</string>
<key>description</key>
<string>Full-service marina and resort with special kayak launch (fee), boat/kayak rentals, charters and ship’s store.\n(239) 542-6222</string>
<key>icons</key>
<string>FMNLJI</string>
</dict>
</array>
</dict>
</plist>
これが私のviewForAnnotationとCallOutAccessoryです:
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation: (id <MKAnnotation>)annotation {
MKPinAnnotationView *pinView = nil;
if(annotation != mapview.userLocation)
{
static NSString *defaultPinID = @"pin";
pinView = (MKPinAnnotationView *)[mapview dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil ) pinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinView.pinColor = MKPinAnnotationColorGreen;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
pinView.rightCalloutAccessoryView = [[UIButton buttonWithType:UIButtonTypeDetailDisclosure] retain];
pinView.backgroundColor = [UIColor clearColor];
} else {
CLLocationCoordinate2D userLoc;
userLoc.latitude = mapview.userLocation.location.coordinate.latitude;
userLoc.longitude = mapview.userLocation.location.coordinate.longitude;
int degrees = userLoc.latitude;
double decimal = fabs(userLoc.latitude - degrees);
int minutes = decimal * 60;
double seconds = decimal * 3600 - minutes * 60;
NSString *lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"", degrees, minutes, seconds];
degrees = userLoc.longitude;
decimal = fabs(userLoc.longitude - degrees);
minutes = decimal * 60;
seconds = decimal * 3600 - minutes * 60;
NSString *longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"", degrees, minutes, seconds];
NSString *coordinate_l = [NSString stringWithFormat:@"%@ %@ %@",lat,@", ",longt];
[mapview.userLocation setSubtitle:coordinate_l];
[mapview.userLocation setTitle:@"Coordinates:"];
}
return pinView;
}
- (void)mapView:(MKMapView *)mapView pinView:(MKAnnotationView *)pinView calloutAccessoryControlTapped:(UIControl *)control {
dViewController = [[detailViewController alloc] initWithNibName:@"detailViewController" bundle:nil];
PlaceMark *theAnnotation = (PlaceMark *) pinView.annotation;
dViewController.descriptiontext = theAnnotation.description;
dViewController.titletext = theAnnotation.title;
dViewController.icontext = theAnnotation.text;
[self presentModalViewController:dViewController animated:true];
[dViewController release];
}
これが私のPlaceMarkクラスです。
@interface PlaceMark : NSObject <MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *currentSubTitle;
NSString *currentTitle;
NSString *currentDescription;
NSString *currentText;
}
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *currentTitle;
@property (nonatomic, copy) NSString *currentSubTitle;
@property (nonatomic, copy) NSString *currentDescription;
@property (nonatomic, copy) NSString *currentText;
- (NSString *)title;
- (NSString *)subtitle;
- (NSString *)description;
- (NSString *)text;
-(id)initWithCoordinate:(CLLocationCoordinate2D) c;
@end
@implementation PlaceMark
@synthesize coordinate,currentTitle,currentSubTitle,currentDescription,currentText;
- (NSString *)subtitle{
return currentSubTitle;
}
- (NSString *)title{
return currentTitle;
}
- (NSString *)description{
return currentDescription;
}
- (NSString *)text{
return currentText;
}
-(id)initWithCoordinate:(CLLocationCoordinate2D) c{
coordinate=c;
NSLog(@"%f,%f",c.latitude,c.longitude);
return self;
}
- (void)dealloc
{
self.currentDescription=nil;
self.currentText=nil;
self.currentSubTitle=nil;
self.currentTitle=nil;
[super dealloc];
}
@end
注釈のカスタムロード関数:
- (void)loadLeeAnnotations{
//retrieve path of plist file and populate relevant types with its information
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Coordinates" ofType:@"plist"];
NSDictionary *rootPlistDict = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
NSMutableArray *arboAnnotations = [[NSMutableArray alloc] init];
//NSMutableDictionary *arboDict = [rootPlistDict objectForKey:key];
NSArray *annotationsArray = [rootPlistDict objectForKey:@"lee"];
CLLocationCoordinate2D workingCoordinate;
for(NSDictionary *annotationContainerDict in annotationsArray){
workingCoordinate.latitude = [[annotationContainerDict objectForKey:@"latitude"] doubleValue];
workingCoordinate.longitude = [[annotationContainerDict objectForKey:@"longitude"] doubleValue];
//NSLog(@"latitude: %f Longitude %f",workingCoordinate.latitude,workingCoordinate.longitude);
PlaceMark *addAnn = [[[PlaceMark alloc] initWithCoordinate:workingCoordinate] autorelease];
[addAnn setCurrentTitle:[annotationContainerDict objectForKey:@"name"]];
[addAnn setCurrentSubTitle:[annotationContainerDict objectForKey:@"coodinates"]];
[addAnn setCurrentText:[annotationContainerDict objectForKey:@"icons"]];
[addAnn setCurrentDescription: [annotationContainerDict objectForKey:@"description"]];
[arboAnnotations addObject:addAnn];
}//for
//NSLog(@"The content of array is %@",arboAnnotations);
mapview.delegate = self;
[mapview addAnnotations:arboAnnotations];
[arboAnnotations release];
}