-1

IOS を初めて使用するので、プログラムに NSThread を実装する必要がありますが、呼び出すと SIGABRT エラーが表示されます。私の現在のコードは以下のとおりです

XMLParser.m

-(void)loadXML
{
    categories =[[NSMutableArray alloc]init];
    NSString *filepath =[[NSBundle mainBundle]pathForResource:@"cd_catalog" ofType:@"xml"];
    NSData *data =[NSData dataWithContentsOfFile:filepath];
    parser=[[NSXMLParser alloc]initWithData:data];
    parser.delegate =self;
    [parser parse];
}

ViewController.m

- (void)viewDidLoad
{
    xmlParser =[[XMLParser alloc]init];
    NSThread *myThread =[[NSThread alloc]initWithTarget:self selector:@selector(loadXML) object:nil];
    [myThread start];
    [super viewDidLoad];
}

私のプログラムの何が問題なのか教えてください

4

4 に答える 4

2

このコードを使用して問題を解決してください...

ViewController.m

- (void)viewDidLoad
{
    NSThread *myThread =[[NSThread alloc]initWithTarget:self selector:@selector(doParsing) object:nil];
    [myThread start];
    [super viewDidLoad];
}
-(void)doParsing
{
    xmlParser =[[XMLParser alloc]init];
    [xmlParser loadXML];
}
于 2013-03-18T05:29:34.383 に答える
0

loadXMLはViewControllerで定義されていないため、スレッドコードを変更して、次のように自分自身ではなくXMLParserのインスタンスを使用する必要があります。

XMLParser *parser = [[XMLParser alloc] init];
NSThread *thread = [[NSThread alloc] initWithTarget:parser selector:@selector(loadXML) object:nil];
[thread start];
于 2013-03-18T05:33:13.913 に答える
0

オブジェクトを作成する代わりに、NSThread次を使用してスレッドを開始できます

//performSelectorInBackground:withObject: is NSObject's method
[self performSelectorInBackground:@selector(loadXML) withObject:nil];

バグのあるコードは見つかりませんでしたが、有効にNSZombieして、これを引き起こしているオブジェクトを確認してください。

于 2013-03-18T05:27:08.953 に答える