【发布时间】:2012-01-03 20:02:41
【问题描述】:
所以我在 This Tutorial 工作,并尝试使用自建 api 将 XML 阅读器构建到我的应用程序中。我正在尝试通读 xml,并不断收到此错误:
*** -[CFString release]: message sent to deallocated instance 0x68675a0
我不会释放或释放任何东西,我会让 AutoRelease 处理所有这些。这是我对该方法的调用:
self.dtContact = [DTContactParser loadDTC];
if (_dtContact != nil) {
for (DTContact *dtc in _dtContact.contacts) {
NSLog(@"%@", dtc.description);
}
}
NSLog(@"done");
我在这结束时收到我的错误,当它发送NSLog(@"done"); 时,它会抛出错误。
这里是 DTContactParser 的 loadDTC
+ (DTCXMLResponse *)loadDTC {
NSString *filePath = [self dataFilePath:FALSE];
NSData *xmlData = [[NSMutableData alloc] initWithContentsOfFile:filePath];
NSError *error;
GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:xmlData
options:0 error:&error];
if (doc == nil) { return nil; }
DTCXMLResponse *dtcxmlr = [[DTCXMLResponse alloc] init];
NSArray *dtcontacts = [doc.rootElement elementsForName:@"DetectiveContact"];
for (GDataXMLElement *dtcontact in dtcontacts) {
// Let's fill these in!
NSString *description;
int dtcid;
// Name
NSArray *descriptions = [dtcontact elementsForName:@"description"];
if (descriptions.count > 0) {
GDataXMLElement *firstName = (GDataXMLElement *) [descriptions objectAtIndex:0];
description = firstName.stringValue;
} else continue;
// Level
NSArray *ids = [dtcontact elementsForName:@"idDetectiveContact"];
if (ids.count > 0) {
GDataXMLElement *firstID = (GDataXMLElement *) [ids objectAtIndex:0];
dtcid = firstID.stringValue.intValue;
} else continue;
DTContact *dtcontact = [[DTContact alloc] initWithName:description dtId:dtcid];
[dtcxmlr.contacts addObject:dtcontact];
return nil;
} }
这里是 DTContact:
#import "DTContact.h"
@implementation DTContact
@synthesize description = _description;
@synthesize dtId = _dtId;
- (id)initWithName:(NSString *)description dtId:(int)dtId{
if ((self = [super init])) {
self.description = description;
self.dtId = dtId;
}
return self;
}
@结束
任何帮助将不胜感激。
【问题讨论】:
标签: objective-c xml-parsing autorelease