1

我似乎无法弄清楚为什么我会收到这个错误并且很难过自己:

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];
}
4

2 回答 2

0

我把它修好了谢谢安娜!关于删除的评论

[addAnn release];

从自定义注释加载类似乎已经解决了这个问题。现在我需要让我的注释弹出窗口显示它们似乎不可点击并且当我点击它们时什么也不做。

于 2012-10-05T02:57:18.520 回答
0

该错误通常意味着坐标无效。
纬度必须介于 -90 到 90 之间,经度必须介于 -180 到 180 之间。

也许代码使用纬度的经度值,反之亦然(或者 plist 中的值可能是向后的)?

于 2012-10-04T15:55:52.560 回答