NSXMLParser not adding objects

不问归期 提交于 2019-12-24 19:15:46

问题


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?


回答1:


Your code call still your app delegate

Try with this kind of code

@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;
}

And set the delegate with self in your constructor



来源:https://stackoverflow.com/questions/8245407/nsxmlparser-not-adding-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!