사용자가지도의 모든 핀을 켜고 끌 수 있어야하는 iPhone 응용 프로그램을 작성 중입니다. 지도에있는 모든 핀을 넣으려면 내가 사용 : 그것은 한 번에 모든 핀을 제거하고 다시 추가 잘 작동MKAnnotations를 제거하는 중 EXC_BAD_ACCESS
-(void) removeAllPins {
NSMutableArray *toRemove = [NSMutableArray arrayWithCapacity:([_mapView.annotations count] - 1)];
for (id annotation in _mapView.annotations) {
if (annotation != _mapView.userLocation) {
[toRemove addObject:annotation];
}
}
[_mapView removeAnnotations:toRemove];
}
:
-(void) putAllPins {
for (id key in myDictionary) { //A NSDictionary
NSArray *data = [myDictionary objectForKey:key];
[self putPin: data];
}
isShowingAllPins = TRUE;
}
-(CLLocationCoordinate2D) putPin:(NSArray *) data {
NSNumber *lat = [data objectAtIndex:0];
NSNumber *lon = [data objectAtIndex:1];
NSString *name = [data objectAtIndex:2];
NSString *info = [data objectAtIndex:3];
CLLocationCoordinate2D coords = {[lat doubleValue], [lon doubleValue]};
MyMapAnnotation *annotation = [[MyMapAnnotation alloc] initWithCoordinate:coords andName:name andInformation:info];
[_mapView addAnnotation:annotation];
[annotation release];
return coords;
}
내가 사용을 제거합니다. 하지만 두 번째로 제거하면 EXC_BAD_ACCESS 오류가 발생합니다. 주석 클래스에서 dealloc 메서드로 문제를 추적했지만 여전히 무엇을해야할지 모릅니다. 어떤 도움을 주셔서 감사합니다!
MyAnnotation.m : 여기
@implementation MyAnnotation
@synthesize coordinate = _coordinate;
-(id) initWithCoordinate:(CLLocationCoordinate2D)coordinate andName:(NSString *)name andInformation:(NSString *)info {
self = [super init];
_coordinate = coordinate;
_name = name;
_info = info;
return self;
}
-(NSString *)title {
return [NSString stringWithFormat:@"PREFIX %@", _name];
}
-(NSString *)subtitle {
return _info;
}
- (void)dealloc {
[_name release];
[_info release];
[super dealloc];
}
@end
흠, _name 및 _info는 절대로 보존되지 않으며 이는 dealloc 메소드가 전혀 존재하지 않아야 함을 의미합니다. 그것을 제거한 후에 모든 것이 잘 작동합니다. 이것을 지적 해 주셔서 감사합니다! –
정확하지 않습니다. 이러한 문자열이 클래스에서 할당 해제되지 않도록하는 것은 무엇입니까? 정상적인 것은 당신이 그들에게 메시지를 나중에 보내고 dealloc에서 해제하기를 원하면 그들을 유지하는 것입니다. 유지/릴리스의 균형을 유지해야합니다. –