2012-10-04 14 views
1

我似乎無法弄清楚,爲什麼我得到這個錯誤,並已難倒自己:使用自定義疊加從plist中加載多個批註

一個實例類標的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]; 
} 

這裏是我的地標級:

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

回答

0

我把它修好了謝謝安娜!刪除評論

[addAnn release]; 

從自定義註釋加載類似乎已經解決了問題。現在我需要讓我的註釋彈出窗口顯示它們似乎不可點擊,並且當我點擊它們時什麼也不做。

+0

我明白了所有的工作,謝謝! –

0

該錯誤通常表示座標無效。
緯度必須從-90到90和經度必須是從-180至180。

也許代碼使用緯度和反之亦然的經度值(或可能在plist中的值是向後)?

+0

我不認爲這是我的問題,因爲其中一個疊加正確加載。我在代碼中添加了上面的plist。 –

+0

「overlay」是否意味着PlaceMark註釋?您能否展示如何創建地圖並將其添加到地圖? – Anna

+0

我添加了自定義的加載註釋函數,當它們從PickerView中選擇他們想要查看的地圖時,運行它們。didSelectRow –