我有这样的代码
- (IBAction)onClick:(id)sender {
NSThread *thread = [[NSThread alloc]initWithTarget:parser selector:@selector(adapter:) object:ph];
[thread start];
}
我通过线程执行选择器之后如何做某事(显示日志或smth)?
答案 0 :(得分: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]];
}