2 garaster garaster 于 2012.10.17 16:41 提问

在背景线程中处理数据

我写了一方法如下:

- (BOOL)shouldDoSomeWork {
   BOOL result = // here I need do hard work with data in background thread and return result, so main thread should wait until the data is calculated and then return result;
   return result;
}

如何实现?

1个回答

g989_1314125
g989_1314125   2012.10.18 17:20
已采纳
-(void) startWork
{ 

    [NSThread detachNewThreadSelector:@selector(doSomeWork) toTarget:self withObject:nil];
}

-(void) doSomeWork
{
    NSAutoreleasePool *pool = [NSAutoreleasePool new];

    [pool release];
    [self performSelectorOnMainThread:@selector(doneWork) withObject:nil waitUntilDone:NO];
}  

-(void) doneWork
{

}
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!