Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 解析XML文件-我疯了_Objective C_Ios_Ios6_Nsxmlparser - Fatal编程技术网

Objective c 解析XML文件-我疯了

Objective c 解析XML文件-我疯了,objective-c,ios,ios6,nsxmlparser,Objective C,Ios,Ios6,Nsxmlparser,我已经浏览了所有地方,包括这里和谷歌,以找到一种为iOS6解析XML文件的简单方法。我发现的每件事都与下一件稍有不同,这让我感到极度困惑。到目前为止,这就是我所拥有的: XMLParser.h #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @class Profile; @interface XMLParser : NSObject <NSXMLParserDelegate>{

我已经浏览了所有地方,包括这里和谷歌,以找到一种为iOS6解析XML文件的简单方法。我发现的每件事都与下一件稍有不同,这让我感到极度困惑。到目前为止,这就是我所拥有的:

XMLParser.h

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@class Profile;

@interface XMLParser : NSObject <NSXMLParserDelegate>{
    NSData *profileData;

@private
    Profile *currentProfileObject;

    NSMutableArray *currentParsedBatch;
    NSMutableArray *currentParsedCharacterData;

    BOOL accumlatingParsedCharacterData;
    BOOL didAbortParsing;

    NSUInteger parsedProfilesCounters;
}

@property (copy, readonly) NSData *profileData;

-(id)initWithData:(NSData *)parseData;

@end
所有这些似乎都不起作用,因为我没有从日志中得到任何响应。如果你不知道的话,这是我写的第一个iOS应用程序,所以我不知道该怎么做。再一次,当我开始失去信心时,我非常感谢你的帮助

  • 如果您认为调用
    [[XMLParser alloc]init]
    将导致执行
    XMLParser
    main
    方法,那么您就错了。若你们想调用该类的任何方法,你们应该对该类的实例进行引用,然后调用所需的方法。例如,在您的情况下:

    XMLParser *parser = [[XMLParser alloc] initWithData:xmlData];
    [parser main];
    [parser release];
    
  • 您的代码中还有很多其他bug,需要花很多时间来讨论。这就是为什么我建议大家阅读苹果文档中的一些简单示例,即。如果您不熟悉类和对象,您也应该阅读


  • 我感谢你的帮助……是的,我在OO编程方面的经验有限。昨晚我终于灵光一现,解析了XML文件。这是在XMLParser.m文件中完成的-现在我只需要弄清楚如何访问MasterViewController.m文件中的数组。@您可以创建
    @property(nonatomic,retain)NSArray*parsedObjects-(id)initWithData:(NSData*)parsedData之前的
    XMLParser
    中的code>。在
    MasterViewController
    中,保存对
    XMLParser
    对象的引用。您可以通过
    parser.parsedData
    检索它;好极了开始工作了!非常感谢你的帮助。我有一个格式问题,我将发布另一个问题。再次感谢你的帮助。
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
    
        NSString *xmlFile = [[NSBundle mainBundle] pathForResource:@"profileXML" ofType:@"xml"];
        NSData *xmlData = [[NSData alloc] initWithContentsOfFile:xmlFile];
    
        [[XMLParser alloc] init];
    
    
        MediDirectoryMasterViewController *masterViewController = [[MediDirectoryMasterViewController alloc] initWithNibName:@"MediDirectoryMasterViewController" bundle:nil];
        self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
        self.window.rootViewController = self.navigationController;
        [self.window makeKeyAndVisible];
        return YES;
    }
    
    XMLParser *parser = [[XMLParser alloc] initWithData:xmlData];
    [parser main];
    [parser release];