'NSXMLParser'没有可见的@interface声明了选择器parseXML

时间:2013-02-14 00:17:22

标签: xcode interface nsxmlparser

我有这些文件:

XMLParser.h

#import <Foundation/Foundation.h>

 @interface XMLParser : NSObject <NSXMLParserDelegate>
{

    NSXMLParser *parser;

}

-(id)initWitData:(NSData *)data;
-(void)parseXML;


@end

XMLParser.m(部分内容)

 #import "XMLParser.h"
 @implementation XMLParser

- (id)initWitData:(NSData *)data
 {
    if (self = [super init]) {

    parser = [[NSXMLParser alloc] initWithData:data];

    [parser setDelegate:self];
}
return self;
}


 - (void)parseXML{

[parser parse];

 };

ViewController.h

#import <UIKit/UIKit.h>
#import "XMLParser.h"

@interface ViewController : UIViewController <CLLocationManagerDelegate>
{

   NSXMLParser *xmlToString;
}


@end

和ViewController.m

 #import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];
NSString *xmlFilePath = [[NSBundle mainBundle] pathForResource:@"world" ofType:@"xml"];

NSData *data = [[NSData alloc]initWithContentsOfFile:xmlFilePath];
xmlToString = [[NSXMLParser alloc]initWithData:data];
//[xmlToString setDelegate:self];
[xmlToString setShouldResolveExternalEntities:YES];
[xmlToString parseXML]; // I am getting the error here.

}

任何人都可以帮助我吗?我在其他项目和它的工作中做了差不多!唯一的区别是initWithData

1 个答案:

答案 0 :(得分:2)

您正在创建NSXMLParser,然后尝试从XMLParser调用方法。您确定并不是要将xmlToString声明为XMLParser*然后说

xmlToString = [[XMLParser alloc] initWithData:data];

当然,您对-setShouldResolveExternalEntities:的调用将失败,因此您可能需要公开基础NSXMLParser对象。