1

私はこのようなコードを持っています

- (IBAction)onClick:(id)sender {

    NSThread *thread = [[NSThread alloc]initWithTarget:parser selector:@selector(adapter:) object:ph];

    [thread start];
}

スレッドがセレクターを実行した後に何かを行うにはどうすればよいですか (ログを表示するか、smth を実行します)。

4

1 に答える 1

2

残念ながら、GCD (サポートできない可能性がある iOS 4.x の機能) を使用せずにこの質問に簡単に答えることはできないためNSNotificationCenter、メソッドが完了したら、通知を使用してラッチします。

- (IBAction)onClick:(id)sender {

    NSThread *thread = [[NSThread alloc]initWithTarget:parser selector:@selector(adapter:) object:ph];

    [thread start];
}

-(void)adapter:(NSObject*)arg {
    //... process and such
    [[NSNotificationCenter defaultCenter]postNotification:[NSNotification notificationWithName:@"Thread_Done" object:nil]];

}
于 2012-06-22T15:20:45.990 に答える