안녕하세요 여러분,이 코드는 NSOperation의 하위 클래스 인 클래스 안에 있습니다 :NSMutableArray에 객체를 추가 할 수 없음
//...
@implementation DataLoader
@synthesize addedAnnotations;
@synthesize addedOverlays;
@synthesize loaderFunc;
@synthesize DLDelegate;
//...
-(id)initWithFunction:(LoaderFunc)func withDelegate:(id)delegate {
if (self = [super init]) {
self.addedOverlays = nil;
self.addedAnnotations = nil;
self.loaderFunc = func;
self.DLDelegate = delegate;
return self;
}
return nil;
}
//...
//inside a function
for (ParkingAnnotations *annotation in fetchedObjects) {
ParkingAnnotation *parkingAnnot = [[ParkingAnnotation alloc] init];
workingCoordinate.latitude = [[annotation latitude] doubleValue];
workingCoordinate.longitude = [[annotation longitude] doubleValue];
[parkingAnnot setCoordinate:workingCoordinate];
[parkingAnnot setTitle:[annotation valueForKey:@"lotName"]];
[parkingAnnot setAnnotationType:[annotation iconTypeRaw]];
[self.addedAnnotations addObject:parkingAnnot];//parkingAnnot not added to array here
[parkingAnnot release];
}
//...
추가 된 주석은 NSMutable 배열입니다. 디버거로이 코드를 살펴 봤는데 어떤 이유로 parkingAnnot 객체가 배열에 추가되지 않습니다. 다음은 클래스의 관련 헤더 코드입니다.
//...
@interface DataLoader : NSOperation {
NSMutableArray *addedAnnotations;
NSMutableArray *addedOverlays;
LoaderFunc loaderfunc;
id <DataLoaderProtocol> DLDelegate;
}
@property (nonatomic, retain) NSMutableArray* addedAnnotations;
@property (nonatomic, retain) NSMutableArray* addedOverlays;
@property (nonatomic) LoaderFunc loaderFunc;
@property (assign) id DLDelegate;
//...
문제가 발생한 함수가 내 MapViewController에서 복사 되었기 때문에 근본적으로 같지만 mapView addAnnotation:
대신 NSMutable 배열에 대신. 무슨 일이야? 미리 감사드립니다!
ParkingAnnotation initializer에 대한 코드를 게시 할 수 있습니까? 아무 일도 일어나지 않을 겁니다. –
self.addedAnnotations를 할당했습니다. For 루프 전에 할당하십시오. self.addedAnnotations = [[nsmutablearray alloc] init]; –
init 함수의 시작 부분에 다음 줄이 있습니다 :'self.addedAnnotations = nil;'실제로이 변수를 다른 곳의 가변 배열로 설정 하시겠습니까? 아니면 그것에 추가하려고 할 때 그것은 아무것도 아닌가요? –