为什么初始化解析器...
- 在 TVC 而不是应用委托中
将解析后的值直接写入解析器委托,在 .h 中声明:
@interface TVC:UITableViewController{ NSMutableArray *parsedDataArray; } @property (nonatomic, weak) NSMutableArray *parsedDataArray;
...在尝试使用所述 TVC 中的解析值时导致 NULL 值断点? 像这样:
NSDictionary *topicsDict = [NSDictionary dictionaryWithObject:parsedResult forKey:@"News"];
当断点关闭时,我们在输出中得到这个:
2013-05-31 01:38:28.256 app[2383:c07] parsedDataArray: (null)
2013-05-31 01:38:28.257 app[2383:c07] *** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '***
-[__NSPlaceholderDictionary initWithObjects:forKeys:count:]:
attempt to insert nil object from objects[0]'
*** First throw call stack:
(0x16f4012 0x14f8e7e 0x16baa95 0x16c8946 0x7943 0x51e1c7 0x51e232 0x51e4da 0x5358e5
0x5359cb 0x535c76 0x535d71 0x53689b 0x5369b9 0x536a45 0x63c20b 0x48d2dd 0x150c6b0
0x121fc0 0x11633c 0x121eaf 0x52c2bd 0x474b56 0x47366f 0x473589 0x4727e4 0x47261e
0x4733d9 0x4762d2 0x52099c 0x46d574 0x46d76f 0x46d905 0x476917 0x4976 0x43a157
0x43a747 0x43b94b 0x44ccb5 0x44dbeb 0x43f698 0x2618df9 0x2618ad0 0x1669bf5 0x1669962
0x169abb6 0x1699f44 0x1699e1b 0x43b17a 0x43cffc 0x464d 0x1f85)
libc++abi.dylib: terminate called throwing an exception
解析器
- (Parser *) initXMLParser {
TVC *tvc = [[TVC alloc] init];
NSString *xmlPath = [[NSBundle mainBundle] pathForResource:@"categorial" ofType:@"xml"];
NSData *xmlData = [NSData dataWithContentsOfFile:xmlPath];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:xmlData];
[xmlParser setDelegate:tvc];
return self;
以下是我如何分配解析器数组 tvc.parsedDataArray = [[NSMutableArray alloc] init];
...它们也在TVC的实现中被合成...
如果还有什么我应该知道或与您分享以解决此问题,请告诉我。