Ios 调用将在指向函数的指针上启动NSThread的函数

Ios 调用将在指向函数的指针上启动NSThread的函数,ios,objective-c,nsthread,Ios,Objective C,Nsthread,我正在尝试用ObjectiveC做一些事情(这远远不是我所知道的语言),我不确定这是否可能 我有一个接口QAFeatTestCaseBase,带有一个函数,该函数将创建一个线程并在其中启动一个函数,然后等待它完成: - (void)callInBackground:(id)target selector:(SEL)selector { NSThread* thread = [[NSThread alloc] initWithTarget:self selector:@selector(

我正在尝试用ObjectiveC做一些事情(这远远不是我所知道的语言),我不确定这是否可能

我有一个接口QAFeatTestCaseBase,带有一个函数,该函数将创建一个线程并在其中启动一个函数,然后等待它完成:

- (void)callInBackground:(id)target selector:(SEL)selector
{  
   NSThread* thread = [[NSThread alloc] initWithTarget:self selector:@selector(selector) object:nil];
   [thread setStackSize: 2*1024*1024];
   [thread start];

   while([thread isFinished] == NO) { usleep(1000); }
   [thread release];
} 
然后我继承它来实现一个特定测试的函数:

@interface Bug8772 : QAFeatTestCaseBase
- (void) testBug8772
{
   [self callInBackground:self selector:@selector(Bug8772)];
}

- (void)Bug8772
{
    // do stuff..
}
但我有一个错误:捕获了NSInvalidArgumentException[NSThread initWithTarget:selector:object:]:target未实现选择器(***-[Bug8722 selector])


你能告诉我我做错了什么吗?或者是否有更好的方法来实现这一点?

选择器
已经是一个选择器。不要用
@selector
包装它

- (void)callInBackground:(id)target selector:(SEL)selector
{  
    NSThread* thread = [[NSThread alloc] initWithTarget:self selector:selector object:nil];
   [thread setStackSize: 2*1024*1024];
   [thread start];

   while([thread isFinished] == NO) { usleep(1000); }
   [thread release];
}

注意,
NSThread
很难正常工作。我认为上面的代码不能满足您的要求


要获得更好的答案,请查看。调度也称为GCD或Grand Central调度。

没错,但即使没有@selector,我也有同样的错误。我不能使用GCD,因为我需要设置堆栈大小,而且GCD不允许。经过一段时间的斗争,我让它工作了。当然,@selector在这里没有任何作用,不知何故,我调用了@selector(Bug8772:)而不是@selector(Bug8772),这将导致找不到选择器的问题。