XML解析期间EXC_BAD_ACCESS(code = 2)

时间:2013-11-27 06:50:26

标签: ios nsxmlparser

 #import "LocationParser.h"

 @implementation LocationParser

-(LocationParser *)initXMLParser
{
 self=[super init];
 if (self)
{
    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];
    self.parsingArray = [NSMutableArray arrayWithArray:appDelegate.presenceArray];
    //parser = [[NSXMLParser alloc]init]; // this was the wrong place to declare. 
    [self parseArrayofPresence];
}
   return self;
}
-(void)parseArrayofPresence
{
 for (NSData *data in _parsingArray)
{     NSLog(@"presence data for parsing is :- %@",data);//this shows the data in NSData form.
      parser = [[NSXMLParser alloc]initWithData:data]; // this solves the problem
 }
    [parser setDelegate:self];
    [parser parse];   // this gets highlighted showing EXC_BAD_ACCESS.

 }

这是我获取数据的AppDelegate类。

   - (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence
   {
       if ([presence status]!= nil) {
      _presenceData = [[presence status] dataUsingEncoding:NSUTF8StringEncoding];//convert presence to NSData
      [_presenceArray addObject:_presenceData]; // add NSData to a mutable array
    locationParser = [[LocationParser alloc]initXMLParser];  //initialising location parser class
   }

1 个答案:

答案 0 :(得分:0)

尝试搬出你的 [parser setDelegate:self]; [parser parse];

out for for循环..顺便问一下你为什么要在for循环中这样做?