我有这个文件:
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];
};
视图控制器.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