这是我的第一个问题,请原谅我犯了什么错误!
在我的iPhone项目中,我有一个在线程中运行的方法,它需要很长时间才能执行(这就是为什么它在线程中运行)。
[NSThread detachNewThreadSelector:@selector(methodToBeCalledInAThread) toTarget:self withObject:nil];
// ...
-(void)methodToBeCalledInAThread {
MyClass *myClass = [[MyClass alloc] init];
[myClass setDelegate:self];
[myClass veryIntensiveComputing];
[myClass release];
}
我的目标是通知调用此方法的ViewController此方法中正在进行的任何进度。这就是为什么我将ViewController设置为类的委托。
if(self.delegate != nil) {
[self.delegate madeSomeProgress];
}
但不幸的是,这不起作用,因为(我认为)我在一个背景线程。