私は常に EXC_BAD_ACCESS を取得していますが、その理由がわかりません...
簡単なタスク:
パーサー クラスは、listArray と呼ばれる NSMutableArray で touchXML を使用して XML を渡します。メソッドgrabCountryでは、listArrayにアクセスでき、listArray.countはうまく機能します。
ここで、MasterViewController という別のクラスに listArray.count が必要です。しかし、常に EXC_BAD_ACCESS エラーが発生します。助けてください!
コード スニペットは次のとおりです。 Parser.h
#import <Foundation/Foundation.h>
@interface Parser : NSObject
@property (strong, retain) NSMutableArray *listArray;
@property (strong, retain) NSURL *url;
-(void) grabCountry:(NSString *)xmlPath;
@end
パーサー.m
#import "Parser.h"
#import "TouchXML.h"
@implementation Parser
@synthesize listArray;
@synthesize url;
-(void) grabCountry:(NSString *)xmlPath {
// Initialize the List MutableArray that we declared in the header
listArray = [[NSMutableArray alloc] init];
// Convert the supplied URL string into a usable URL object
url = [NSURL URLWithString: xmlPath];
//XML stuff deleted
// Add the blogItem to the global blogEntries Array so that the view can access it.
[listArray addObject:[xmlItem copy]];
//works fine
NSLog(@"Amount: %i",listArray.count);
}
@end
MasterViewController.h
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "TouchXML.h"
#import "Parser.h"
@class Parser;
@interface MasterViewController : UITableViewController{
Parser *theParser;
}
@end
MasterViewControlelr.m
- (void)viewDidLoad
{
NSString *xmlPath = @"http://url/to/xml.xml";
theParser = [[Parser alloc] init];
//Starts the parser
[theParser grabCountry:xmlPath];
//Here I want to access the Array count, but getting an BAD ACCESS error
NSLog(@"Amount %@",[theParser.listArray count]);
[super viewDidLoad];
}
ここで何が問題なのか誰か説明してもらえますか? ありがとう!