NSXMLParser 不添加对象 [英] NSXMLParser not adding objects
问题描述
我是 NSXMLParser 的新手,所以我决定学习本教程:http://www.xcode-tutorials.com/parsing-xml-files/ 很棒.但是在我的应用程序中,我不是在 AppDelegate 中使用解析器,而是在其他 ViewController 中使用解析器.我将初始化更改为:
I'm new to the NSXMLParser, so I decided to take this tutorial: http://www.xcode-tutorials.com/parsing-xml-files/ and it was great. But in my app I used parser not in AppDelegate, but in other ViewController. I changed initialization to this:
-(XMLParser *)initXMLParser {
[super init];
viewController = (ViewController *)[[UIApplication sharedApplication] delegate];
return self;
}
解析器本身运行良好,但它不会将任何对象添加到应添加对象的视图控制器中的数组中.有人可以帮忙吗?
The parser itself works well but it doesn't add any objects to the array in view controller in which the objects should be added. Can anyone help?
推荐答案
你的代码仍然调用你的应用委托
Your code call still your app delegate
试试这种代码
@interface XMLParser : NSObject {
NSMutableString *currentElementValue;
id<NSXMLPArserDelegate> delegate;
Book *aBook;
}
-(XMLParser *)initXMLParserWithDelegate:(id<NSXMLPArserDelegate>) delegate;
@end;
-(XMLParser *)initXMLParserWithDelegate:(id<NSXMLPArserDelegate>) _delegate {
self = [super init];
if(self) {
delegate = _delegate;
}
return self;
}
并在构造函数中使用 self 设置委托
And set the delegate with self in your constructor
这篇关于NSXMLParser 不添加对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!