私は私を怒らせている問題に取り組んでいます。他のフォーラムを調べたところ、私のコードは問題ないように見えますが、NSMutableArray の addObject メソッドを呼び出すと失敗します。単純な xml パーサー クラスを実装し、一部の情報を NSMutableArray に格納しています。
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if([elementName isEqualToString:@"Image"]){
[images setObject: [[imageFile copy] autorelease] forKey: [NSNumber numberWithInt: imageId]];
return;
}
if([elementName isEqualToString:@"Annotation"]){
//Here create the annotation object
Annotation *newAnnot = [[Annotation alloc] init];
newAnnot.imageId = imageId;
newAnnot.annDescription = [[annDescription copy] autorelease];
newAnnot.annLocation = [[annLocation copy] autorelease];
[annotations addObject: newAnnot];
[newAnnot release];
return;
}
if([elementName isEqualToString: @"Patient"] || [elementName isEqualToString: @"Images"] || [elementName isEqualToString: @"Annotations"]){
[currentSection setString: @""];
}else {
[currentElement setString: @""];
}
}
[annotations addObject: newAnnot] アプリケーションが SIGABRT シグナルを受信するようにしています!
2010-11-08 17:15:00.786 Touches[1430:207] *** -[NSCFDictionary addObject:]: unrecognized selector sent to instance 0x4b1bb50 2010-11-08 17:15:00.788 Touches[1430:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFDictionary addObject:]: unrecognized selector sent to instance 0x4b1bb50' 2010-11-08 17:15:00.789 Touches[1430:207] Stack: (
42174544,
43332396,
42183259,
41645686,
41642482,
18858,
39384333,
70873863,
70897681,
39381417,
17100,
8863,
2234926,
38538931,
38537114,
2234111,
38538931,
38544407,
38545466,
38538931,
38537114,
2230794,
2239193,
103026,
108372,
134462,
115959,
147928,
44216700,
41453724,
41449640,
107041,
140146,
8296 ) terminate called after throwing an instance of 'NSException' Program received signal: “SIGABRT”. (gdb) continue Program received signal: “SIGABRT”.
コードの簡単な説明は次のとおりです。
Annotation は、NSObject から派生した単純なクラスです。init メソッドと dealloc メソッドを実装しています。最初のものは何もせず、単に "self" を返しますが、dealloc は親を呼び出して 2 つの文字列を解放します
@interface Annotation : NSObject {
int imageId;
NSString *annDescription;
NSString *annLocation;
}
@property (nonatomic, assign) int imageId;
@property (nonatomic, retain) NSString *annDescription;
@property (nonatomic, retain) NSString *annLocation;
ここまでは何もおかしくない。次に、解析を実装するクラスを見てください。
@interface PatientBundle : NSObject <NSXMLParserDelegate> {
//............
NSMutableArray *annotations;
//.............
}
@property (nonatomic, retain) NSMutableArray *annotations;
私のinitメソッドは次のようになります:
- (id) initFromFile: (NSString*)pathToFile{
//.....
annotations = [[NSMutableArray alloc] initWithCapacity: 10];
[addressParser setDelegate:self];
//......
}
デバッグは、「注釈」配列に追加しているオブジェクトが nil ではないことを示唆していますが、最初のオブジェクトを挿入することさえできません。NSInvalidArgumentException が発生するのはなぜですか? 私の配列がクラス NSMutableArray の場合、なぜ NSCFDictionary :addObject なのですか? 私が見逃している NSMutableArray の使用について何かありますか?
私のプラットフォームの詳細: - iphone Simulator バージョン 4.1 (225) を実行しています - ベース SDK と展開ターゲット: iOSDevice 4.1 (ターゲット IPAD) - GCC 4.2
手がかりをいただければ幸いです。前もって感謝します。
ルイス